-1

I'm trying to match lines that do not begin with "CD" or any 2-digit number. I've tried:

^[^Cc0-9][^Dd0-9].+?$

but it does not match lines that begin with "Cx" or "0y".

I'm using a program called rxrepl with the above regex as the search string and nothing as the replacement. I'm trying to avoid using grep. Also I can't use parentheses because in rxrepl they are used to capture groups.

ikegami
  • 322,729
  • 15
  • 228
  • 466
zcalebz
  • 139
  • 10

2 Answers2

3

As others have said, you need

^(?:CD|\d\d)

The (?: ... ) is a non-capturing group

Or if you must avoid parentheses of any sort then use

^CD|^\d\d


Update

To comply with your new spec "I'm actually trying to match lines not beginning with CD or 2 digit numbers"

^(?!CD|\d\d)

You need to get over your problem with the parentheses. A negative look-ahead is fine in PCRE and does not capture

Community
  • 1
  • 1
Borodin
  • 123,915
  • 9
  • 66
  • 138
2

It is either CD or two numbers. So you have to use groups (group1|group2) like this:

^(CD|[0-9]{2})
# ^^ ^^^^^^^^
# |         |   
# either CD |
#           or two digits
fedorqui 'SO stop harming'
  • 228,878
  • 81
  • 465
  • 523