Friday, September 30, 2011

python RegularExpression 1

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Demonstrate how to use Regular Expression
import re
#Compile Regular Expression first.
re1 = re.compile('matchBullet')
print re1.match('matchBullet')
print re1.match('matchBullet').group()

re2 = re.compile('matchBala')
match1 = re2.match('matchBala')
print match1.group()

searchstr = "Bala"
re2=re.compile(searchstr)
match1 = re2.match(searchstr)
print match1.group()

#END

Output
bala@bala-laptop:~/python$ python RE.py
<_sre.SRE_Match object at 0x7feb846091d0>
matchBullet
matchBala
Bala
bala@bala-laptop:~/python$

No comments:

Post a Comment