[英]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. 我正在尝试匹配不以“ CD”或任何2位数字开头的行。 I've tried:
我试过了:
^[^Cc0-9][^Dd0-9].+?$
but it does not match lines that begin with "Cx" or "0y". 但与以“ Cx”或“ 0y”开头的行不匹配。
I'm using a program called rxrepl with the above regex as the search string and nothing as the replacement. 我正在使用一个名为rxrepl的程序,上面的正则表达式为搜索字符串,而没有任何替换项。 I'm trying to avoid using grep.
我试图避免使用grep。 Also I can't use parentheses because in rxrepl they are used to capture groups.
另外,我不能使用括号,因为在rxrepl中它们用于捕获组。
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
To comply with your new spec "I'm actually trying to match lines not beginning with CD or 2 digit numbers" 为了符合您的新规范“我实际上是在尝试匹配 不 以CD或2位数字开头的 行 ”
^(?!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
否定的预见在PCRE中很好,并且不能捕获
It is either CD
or two numbers. 它是
CD
或两个数字。 So you have to use groups (group1|group2)
like this: 因此,您必须像这样使用组
(group1|group2)
:
^(CD|[0-9]{2})
# ^^ ^^^^^^^^
# | |
# either CD |
# or two digits
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.