zcalebz zcalebz - 1 year ago 88
Perl Question

Match lines not starting with first two specific characters

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


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.

Answer Source

As others have said, you need


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

Or if you must avoid parentheses of any sort then use



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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download