Quickie - Regexp for a string not at the beginning of the line

Zero Piraeus schesis at gmail.com
Thu Oct 25 17:21:32 EDT 2012


:

On 25 October 2012 16:53, Rivka Miller <rivkaumiller at gmail.com> wrote:
> I am looking for a regexp for a string not at the beginning of the
> line.

There are probably quite a few ways to do this, but '(?<!^)PATTERN'
has the advantage of explicitly describing what you're trying to do.
For instance:

>>> pattern = re.compile(r"(?<!^)\b\w+\b")
>>> re.findall(pattern, "this is some text")
['is', 'some', 'text']

 -[]z.



More information about the Python-list mailing list