[英]ReGex to match exact word, ignoring words containing it as a substring?
I'd like to match all instances of prod
in a large file. 我想在一个大文件中匹配所有
prod
实例。 The file contains arrangements such as: 该文件包含以下安排:
prod
"prod"
.prod
prod.
prod*
(prod
production
I'd like way to match (and ultimately, replace) all instances of the above, except for the last result . 我想要一种匹配(并最终替换)上述所有实例的方法, 最后一个结果除外 。 The best I've come up with so far is just a simple
\\W
: https://regex101.com/r/8bOrcS/1/ 到目前为止,我想出的最好的方法只是一个简单的
\\W
: https : //regex101.com/r/8bOrcS/1/
You may use this regex with alternations to match a word boundary or one of the given non-word characters around prod
: 您可以将此正则表达式与交替使用,以匹配
prod
周围的单词边界或给定的非单词字符之一:
(?:[".(_*-]|\b)prod(?:[".)_*-]|\b)
(?:[".(_*-]|\\b)
matches a word boundary or one of the given special characters. (?:[".(_*-]|\\b)
匹配单词边界或给定的特殊字符之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.