Chapter 22 – Python Regular Expression Part 5

 
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 22 – Regular Expression 5 \n————————————\n"
 
import re
 
in_str = raw_input("Enter a text         : ")
 
se_str = raw_input("Enter search string  : ")
 
re_str = raw_input("Enter replace string : ")
 
count = 2
 
reg1 = re.compile(se_str)
 
print "Result : ",reg1.sub(re_str,in_str,count)
 
print "\n———————————–\n"
 
#END

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

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

Leave a Reply