Chapter 19 – Python Regular Expression Part 2

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 19 – Regular Expression 2 \n————————————\n"
 
import re
match_str = "jijo k 50 JOSE"
search_str = "[a-z]+.*"
 
print "Input String : %s"%match_str
 
print "\n———————————–\n"
 
reg1 = re.compile(search_str,re.IGNORECASE)
match = reg1.match(match_str)
 
print "Address Location : ",reg1.match(search_str)
print "Search string : ",search_str
print "Matched string : ",match.group()
 
print "\n———————————–\n"
 
search_str = '[a-z]+\s[a-z]\s[0-9]+\s\w[A-Z]'
reg1 = re.compile(search_str)
match = reg1.match(match_str)
 
print "Search string : ",search_str
print "Matched string : ",match.group()
 
print "\n———————————–\n"
 
#END

 
Step 2
 
Change file permission to executable using chmod command.
 
Step 3
 
Execute the python file.
 
python-regular-expression-19
 

 
You can leave a response, or trackback from your own site.

Leave a Reply