0

I'm trying to match the first 5 lines, and the last line, in this sample:

-- 2012-09-20 rep +6    = 184       
 1  12532070 (2)
 2  12531806 (5)
 2  12531806 (5)
-- 2012-09-21 rep +12   = 196       
 3  125xxxxx (-1)
 3  125xxxxx (-1)
 16 12557052 (2)

Leaving the following unmatched:

 3  125xxxxx (-1)
 3  125xxxxx (-1)

I've tried the following regular expressions:

^.*[^(-1)\r\n].*
^.*[^(-1)].*\r\n
^.*[^\(-1\)\r\n].*
^.*[^\(\-1\)\r\n].*
^.*[?!\(-1)\r\n].*
^(!?.*-1.*\r\n)

But none of them do what I want (mostly matching all lines).

My RegEx skills are not brilliant - can anybody point me in the right direction?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
  • which language-tool are you using..regex implementation differs across languages – Anirudha May 04 '13 at 13:23
  • @Anirudh Sorry, I hadn't realised RegEx is specific to the language. I'm using Notepad++'s find and replace feature. Sorry about that, I've retagged my question. – Danny Beckett May 04 '13 at 13:24

2 Answers2

1

You can use negative lookahead

^(?!.*\(-1\)$).*$\r\n
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • @DannyBeckett i said it,the regex should be used with multiline option,which tool-language are you using – Anirudha May 04 '13 at 13:21
  • @DannyBeckett `\r\n` after `$` is not right! `$` depicts the end of line and anything after that has no use – Anirudha May 04 '13 at 13:39
0

Rather than trying to create a regular expression for this, I would just use the surrounding language to negate the sense of the match, and use a regex that only matches lines that end in '(-1)\r\n'. For instance:

Shell: grep -v '(-1)^M$'

Perl: !/\(-1\)\r\n/

Ed/Vi: v/(-1)^M$

etc.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • Sorry, I hadn't realised RegEx is specific to the language. I'm using Notepad++'s find and replace feature. Sorry about that, I've retagged my question. – Danny Beckett May 04 '13 at 13:25