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
Step 2
Change file permission to executable using chmod command.
Step 3
Execute the python file.
No comments:
Post a Comment