Kent,
I think \b will work for me since I was really looking for [\A\W] anyway.
That still doesn't answer the generalized question about something like [\A\d] for instance.
I know :-)
The docs say [] is "Used to indicate a set of characters." So it kind of makes sense that it works for \w and \s, which are just shortcuts for sets of characters themselves, but not for \A which is something different.
Kent
Thanks, Jeff
BTW, I was using raw strings although I forgot to put that in.
-----Original Message-----
From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 01, 2005 1:15 PM
Cc: [email protected]
Subject: Re: [Tutor] Matching with beginning of the line in the
character set
Smith, Jeff wrote:
I want to match a string which is preceeded by a space or occurs at the beginning of the line. I also don't want to catch the preceeding character as a group.
I have found both of the following to work re.compile('(?:^|\s)string') re.compile('(?:\A|\s)string')
How about r'\bstring' ? It doesn't mean quite the same as \sstring but it might work for you.
But would prefer to use the more concise [] notation. However re.compile('[^\s]string')
As the first character in [], ^ means 'not'.
Does not work and re.compile('[\A\s]string')
I guess \A doesn't count as a 'character class'? Or do you need to be using raw strings?
Kent
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
