[Tutor] Issues with regex escaping on \{

wesley chun wescpy at gmail.com
Wed Jul 29 22:17:45 CEST 2009


in addition to the good advice from vince (watch out for greediness
regardless of what you're looking for) and bill (use raw strings...
regexes are one of their primary use cases!), another thing that may
help with the greediness issue are the character sets you're using
inside to match with.

for example, if you know the string inside the curly braces, e.g.,
{88F96ED2-D471-DE11-95B6-0050569E7C88}, are numbers and letters and
dashes, you can use "[\w-]+" which means one or more alphanumeric
characters plus the dash. the use of ".+" is just *asking* for greedy
gobbling up of characters like "}" because "." means match any single
character.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list