Reg Exp in Python tutorial

General discussion on technical and managerial topics
no avatar
khl
 
Posts: 1
Joined: Mon May 13, 2013 5:10 pm

Reg Exp in Python tutorial

by khl » Mon May 13, 2013 5:17 pm

Hi

The given example (http://www.tutorialspoint.com/python/py ... ssions.htm) doesn't seem to work.

Backreferences:
This matches a previously matched group again:
([Pp])ython&\1ails Match "python&rails or Python&Rails"

Put this in to the previous Cats example
#!/usr/bin/python
import re

line = "Python&Rails";

matchObj = re.match( r'([Pp])ython&(\1ails)', line, re.M|re.I)

if matchObj:
print "matchObj.group() : ", matchObj.group()
print "matchObj.group(1) : ", matchObj.group(1)
print "matchObj.group(2) : ", matchObj.group(2)
else:
print "No match!!"

it shows
No match!!
[Finished in 0.1s]

Change the line to "Python&Pails" then it's Okay.

Return to General Discussion

cron