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

Devin Jeanpierre jeanpierreda at gmail.com
Fri Oct 26 01:08:06 EDT 2012


On Thu, Oct 25, 2012 at 10:00 PM, Ed Morton <mortonspam at gmail.com> wrote:
> Because there is no solution - there IS no _RE_ that will match a string not
> at the beginning of a line.

Depending on what the OP meant, the following would both work:

- r"^(?!mystring)" (the string does not occur at the beginning)
- r"(?!^)mystring" (the string occurs elsewhere than the beginning)
  [Someone else's interpretation]

Both are "regular expressions" even in the academic sense, or else
have a translation as regular expressions in the academic sense.
They're also Python regexps. So I don't know what you mean.

-- Devin



More information about the Python-list mailing list