Archive for the ‘Python’ Category

Chapter 20 – Python Regular Expression Part 3

 
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 20 – Regular Expression 3 \n————————————\n"
 
import re
 
in_str = raw_input("Enter the text : ")
 
se_str = raw_input("Enter search string : ")
 
reg1 = re.compile(se_str)
 
find1 = reg1.findall(in_str)
 
print "\nOutput of – .findall() : ", find1 
 
print "\n———————————–\n"
 
iter1 = reg1.finditer(in_str)
 
print "Output of – .finditer() : \n"
 
for i in iter1:
 print i.group() 
 
print "\n———————————–\n"
 
#END

Read more »

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

Read more »

Chapter 18 – Python Regular Expression Part 1

 
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 18 – Regular Expression 1 \n————————————\n"
 
import re
match_str = raw_input("Enter a text : ")
search_str = raw_input("Enter search string : ")
 
reg1 = re.compile(search_str,re.IGNORECASE)
 
print "Address Location : ",reg1.match(match_str)
 
print "\n———————————–\n"
 
match = reg1.match(match_str)
 
if match:
 print "Match – Found : ",match.group()
else:
 print "No match found !!! "
 
print "\n———————————–\n"
 
search = reg1.search(match_str)
 
if search:
 print "Search Found : ",search.group()
else:
 print "No searched result !!!"
 
print "\n———————————–\n"
 
#END

Read more »