This question already has an answer here:
这个问题在这里已有答案:
- Regex lookahead for 'not followed by' in grep 6 answers
正则表达式在grep 6答案中预测'未跟随'
I need the below requirement
我需要以下要求
string123
stringsecond
string-third
-string-four
string_five
/string/
sixstring
this should not print
output
string-third
-string-four
string_five
/string/
So as per the output,the command should not grep string followed with alphanumeric only. I am using -w option with grep ,but it is eliminating underscore(_) strings also.
因此,根据输出,命令不应该是grep字符串,后面只有字母数字。我在grep中使用-w选项,但它也消除了下划线(_)字符串。
1 个解决方案
#1
0
Use a negated character class at the end of your regex.
在正则表达式的末尾使用否定的字符类。
If you're matching "string", then append a class like [^0-9a-zA-Z_]
to the end.
如果您匹配“字符串”,则将类似[^ 0-9a-zA-Z_]的类附加到末尾。
#1
0
Use a negated character class at the end of your regex.
在正则表达式的末尾使用否定的字符类。
If you're matching "string", then append a class like [^0-9a-zA-Z_]
to the end.
如果您匹配“字符串”,则将类似[^ 0-9a-zA-Z_]的类附加到末尾。