Alternatively, you could .split() your string and not invoke the mechanisms dealing with regular expressions.
Is this considered stylistically sloppy in the event that the split results in a very long array? Sloppier than REs are to begin with? I think that the problem with [\A\d] is that \A is zero-length, which doesn't make sense in the context of []. Brackets aren't shorthand for "'or' a bunch of small things together" but rather "'or' a bunch of these single-character matches together" mike On Tue, 1 Feb 2005 13:30:44 -0500, Smith, Jeff <[EMAIL PROTECTED]> wrote: > 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. > > 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: Tutor@python.org > 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 - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor