<filename>python_parikshith21/Day22.py
# -*- coding: utf-8 -*-
"""
Created on Tue May 29 14:14:24 2019

@author: Parikshith.H
"""
import re

fhand=open('regular_expression_input.txt')
 
for line in fhand:
    print(line)
    if re.search('X\S*:[0-9.]+',line):
        print(line)
 
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# 
# ABXyz: 808.3.3
# 
# this is ABXyz: 808.3.3 thank you
# 
# this is ABXyz: 808 thank you
# =============================================================================

 
for line in fhand:
    if re.search('X\S*: [0-9]+[.][0-9]+',line):
        print(line)
 
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# 
# ABXyz: 808.3.3
# 
# this is ABXyz: 808.3.3 thank you
# =============================================================================
    

for line in fhand:
    if re.match('X\S*: [0-9]+',line): #match will match pattern at begining only
        print(line)
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# =============================================================================

for line in fhand:
    L=re.findall('[0-9]+',line)
    print(L)
# =============================================================================
# #output:
# ['808', '3']
# ['808', '3', '3', '3']
# ['808', '3', '3']
# ['808', '3', '3']
# ['808']
# =============================================================================

<filename>python_parikshith21/Day22.py
# -*- coding: utf-8 -*-
"""
Created on Tue May 29 14:14:24 2019

@author: Parikshith.H
"""
import re

fhand=open('regular_expression_input.txt')
 
for line in fhand:
    print(line)
    if re.search('X\S*:[0-9.]+',line):
        print(line)
 
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# 
# ABXyz: 808.3.3
# 
# this is ABXyz: 808.3.3 thank you
# 
# this is ABXyz: 808 thank you
# =============================================================================

 
for line in fhand:
    if re.search('X\S*: [0-9]+[.][0-9]+',line):
        print(line)
 
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# 
# ABXyz: 808.3.3
# 
# this is ABXyz: 808.3.3 thank you
# =============================================================================
    

for line in fhand:
    if re.match('X\S*: [0-9]+',line): #match will match pattern at begining only
        print(line)
# =============================================================================
# #output:
# Xyz: 808.3
# 
# Xyz: 808.3.3.3
# =============================================================================

for line in fhand:
    L=re.findall('[0-9]+',line)
    print(L)
# =============================================================================
# #output:
# ['808', '3']
# ['808', '3', '3', '3']
# ['808', '3', '3']
# ['808', '3', '3']
# ['808']
# =============================================================================

# -*- coding: utf-8 -*- Created on Tue May 29 14:14:24 2019  @author: Parikshith.H # ============================================================================= # #output: # Xyz: 808.3 # # Xyz: 808.3.3.3 # # ABXyz: 808.3.3 # # this is ABXyz: 808.3.3 thank you # # this is ABXyz: 808 thank you # ============================================================================= # ============================================================================= # #output: # Xyz: 808.3 # # Xyz: 808.3.3.3 # # ABXyz: 808.3.3 # # this is ABXyz: 808.3.3 thank you # ============================================================================= #match will match pattern at begining only # ============================================================================= # #output: # Xyz: 808.3 # # Xyz: 808.3.3.3 # ============================================================================= # ============================================================================= # #output: # ['808', '3'] # ['808', '3', '3', '3'] # ['808', '3', '3'] # ['808', '3', '3'] # ['808'] # =============================================================================