By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,270 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,270 IT Pros & Developers. It's quick & easy.

whats wrong with my reg expression ?

P: n/a
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

?
Jan 15 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gert Cuykens wrote:
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
Jan 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.