2

I created vim search pattern to find bad status codes:

   / [45][0-9][0-9]  

It can find 504 or 499 or 404 (space before and after each number)

But I don't want it to find 404. How to change my search pattern to make it skip 404?

Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
  • With the given information there's no way for us to create a regex matching your needs. What kind of status codes do you want to match? – Vince Oct 09 '13 at 13:17

2 Answers2

7

Using a negative look-ahead for that number:

/\(.*404\)\@![45]\d\{2\}

UPDATE: Thanks to Karoly Horvath to point out that this regex could fail with some numbers in the same line. Much better:

/\(404\)\@![45]\d\{2\}

Another way with a negative look-behind after the match:

/[45]\d\{2\}\(404\)\@<!
Community
  • 1
  • 1
Birei
  • 35,723
  • 2
  • 77
  • 82
2
5[0-9][0-9]|4[1-9][0-9]|40[0-35-9]

The old-school pattern is:

  • 5 followed by any two digits, OR:
  • 4 not followed by zero, and then any digit, OR:
  • 40 not followed by 4.

I hope you don't have other black-listed codes, because this will get ugly very quickly.

Kobi
  • 135,331
  • 41
  • 252
  • 292
  • I'm probably wrong about the lookahead: http://stackoverflow.com/questions/18391665/vim-positive-lookahead-regex . I'll remove that comment. – Kobi Oct 09 '13 at 13:25