A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/090700.html below:

Regular Expression Question

Regular Expression Question Regular Expression QuestionTim Peters tim.one at home.com
Tue Apr 3 20:42:26 EDT 2001
[Wesley Witt]
> This is probably a simple question, but I can't seem to find the answer
> anywhere.
>
> I want a regular expression that will match ALL lines that do NOT
> contain the string "skip".
> ...

Like everyone else here, I recommend using the string find() method instead,
for this specific case.

More generally, if you *need* a regexp, there's a trivial solution:  don't
screw with the regexp, invert the result of the *test*:

    searcher = re.compile("skip").search
    while 1:
        ...
        if searcher(line):
            # found it
        else:
            # no "skip" in this line!

A funkier way is to fool around with negative lookahead assertions, like

    searcher = re.compile("(?!.*skip)", re.DOTALL).match

This fails to match if it can find "skip", and matches an empty string at the
start if it can't find "skip".

pick-your-poison-but-look-in-the-mirror-as-you're-dying<wink>-ly y'rs
    - tim



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4