[Tutor] New Issues with REGEX Greediness:

gpo goodpotatoes at yahoo.com
Sun Aug 2 20:55:39 CEST 2009


Thanks for the replies in the last thread.  I'm still trying to figure out
how Python is handling RegEx.  I'm converting my thoughts from Perl (the
mother of regex) to Python, and expect the same results.  Why are they
different?

Perl:
$line='>Checking Privilege for UserId:
{874BE70A-194B-DE11-BE5C-000C297901A5}, PrivilegeId: {prvReadSdkMessage}.
Returned hr = 0'
$line=~/(\w+)\:.+.{8}-.{4}-.{4}-.{4}-.{12}/;
print "$1"
RESULT:
UserId

This is the result I want.  I'm trying to get the name's of GUID's from log
files.

Python:
line='>Checking Privilege for UserId:
{874BE70A-194B-DE11-BE5C-000C297901A5}, PrivilegeId: {prvReadSdkMessage}.
Returned hr = 0'
(re.search('(\w+)\:.+.{8}-.{4}-.{4}-.{4}-.{12}',line)).group(0)
RESULT
'UserId: {874BE70A-194B-DE11-BE5C-000C297901A5'

How/Why are these results different?  What is Python doing differently in
regex, that I need to adjust to?  
-- 
View this message in context: http://www.nabble.com/New-Issues-with-REGEX-Greediness%3A-tp24764404p24764404.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list