views:

514

answers:

4

i have the following lines:

Message:Polarion commit Mon May 18 06:59:37 CEST 2009
Message:Polarion commit Fri May 15 19:39:45 CEST 2009
Message:424-18: use new variable
Message:Polarion commit Fri May 15 19:29:10 CEST 2009
Message:Polarion commit Fri May 15 19:27:23 CEST 2009
Message:000-00: do something else
Message:Polarion commit Fri May 15 17:50:30 CEST 2009
Message:401-103: added application part
Message:Polarion commit Fri May 15 17:48:46 CEST 2009
Message:Polarion commit Fri May 15 17:42:04 CEST 2009

and i want to get all the lines NOT containing "Polarion"

how would i do this?

ps: i saw: http://stackoverflow.com/questions/42990/regex-to-match-against-something-that-is-not-a-specific-substring but it doesn't help me

pps: i'm trying to do this in tortoiseSVN to select log messages, and i think there is a problem with "negative lookbehind"

+7  A: 

It might be easier if you make your regular expression match the thing you are looking for and then reverse the results.

Most tools using Regex allow you to reverse the search results, generally calling the option in**v**ert (keeping the i for case-insensitive):

e.g.

grep -v <search>
find /v <search>

etc.

Ray Hayes
Hmmm, the first bold text, the v in invert shows up fine in the preview but looks wrong here...
Ray Hayes
The asterisks aren't meant to be used inside a word, but <b>...</b> should work. This isn't the first time I've seen the preview pane give bogus results.
Alan Moore
+1, this is just what i was looking for
Claudiu
+2  A: 

This expresion will do the job.

^(?:.(?<!Polarion))*$

It uses a zero-width negative lookbehind assertion to assert that the string does not contain "Polarion".

    ^                  Anchor to start of string
    (?:                Non-capturing group
        .              Match any character
        (?<!Polarion)  Zero-width negative lookbehind assertion - text to the
                       left of the current position must not be "Polarion"
    )
    *                  Zero or more times
    $                  Anchor to end of string

The following version will perform the assertion only after a 'n' - maybe this will be faster, maybe slower.

^(?:[^n]*|n(?<!Polarion))*$
Daniel Brückner
Interesting answer, but grep -v is much simpler.
Trampas Kirk
A: 

I could not find any information about what regex engine TortoiseSVN is using, but you might ask on the mailing list. Not all engines support advanced features like zero-width negative look-behind.

Chas. Owens
+2  A: 

Here's a solution using a negative lookahead, which is more widely supported than a lookbehind:

^Message:(?!Polarion).*$

(Also, since we know where Polarion might appear, we don't need to do any of the pointless fancy stuff Daniel suggested.)


Explanation of the above expression, in regex comment form, is:

(?x)       # Enable comments
^          # Start of string (start of line in multiline mode)
Message:   # Literal text
(?!        # Begin negative lookahead
Polarion   # Literal text
)          # End negative lookahead
.*         # Greedily match any number of any character
$          # End of string (end of line in multiline mode)
Peter Boughton