whats wrong with my reg expression ?

G

Gert Cuykens

rex2=re.compile('^"(?P<value>[^]*)"$',re.M)

File "/usr/lib/python2.5/re.py", line 180, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.5/re.py", line 233, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of regular expression

?
 
J

James Stroud

Gert said:
rex2=re.compile('^"(?P<value>[^]*)"$',re.M)

File "/usr/lib/python2.5/re.py", line 180, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.5/re.py", line 233, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of regular expression

?
You probably want

rex2=re.compile('^"(?P<value>[\^]*)"$',re.M)

Because [] is a bracketed group and the ^ within a bracketed group is a
negation, but you have negated nothing before closing the group.
Alternatively:

rex2=re.compile('^"(?P<value>\^*)"$',re.M)

Would have the same meaning, avoiding the bracketed group altogether.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top