匹配每个不包含子字符串的引用字符串
多行测试字符串:
dkdkdkdk dkdkdkdk dkdkdkd dkdkdkd "hello" dkdkdkdkdk dkdkdk "goodbye.hello" dkdkdkd kdkdkd kdkdkdk "hello.goodbye.hello" dddd "test" ssss "http:x-y.f/z/z" "" "."
"http:/dkdkd/dkdkdk/dkdkdkdkdkdk.g"
我想匹配包含“hello
”的每个带引号的字符串
这匹配每个带引号的字符串
\"(.+?)\"
这匹配其中包含 hello 的每个带引号的字符串
\"(.*?)hello(.*?)\"
但这不匹配每个不包含 hello 的带引号的字符串包含你好
\"(.*?)(?!hello)(.*?)\"
感谢您的帮助!
Multiline Test string:
dkdkdkdk dkdkdkdk dkdkdkd dkdkdkd "hello" dkdkdkdkdk dkdkdk "goodbye.hello" dkdkdkd kdkdkd kdkdkdk "hello.goodbye.hello" dddd "test" ssss "http:x-y.f/z/z" "" "."
"http:/dkdkd/dkdkdk/dkdkdkdkdkdk.g"
I want to match every quoted string that contains "hello
"
This matches every quoted string
\"(.+?)\"
This matches every quoted string that contains hello in it
\"(.*?)hello(.*?)\"
But this, does not match every quoted string that DOES NOT contain hello
\"(.*?)(?!hello)(.*?)\"
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最初的答案是每次点匹配时都需要应用负向先行,如下所示:
但是,在包含多个带引号的字符串的目标中,此正则表达式存在问题 - 一个字符串的结束引号与另一个引用的开头字符串也是该表达式的“引用字符串”。
因此,我的建议是使用简单的
"[^"]*"
模式从目标中提取所有带引号的字符串,然后评估您想要禁止的单词的每个匹配项。My initial answer is to need to apply the negative lookahead every time the dot matches, like so:
However there is a problem with this regular expression in targets that contain more than one quoted string -- the space between the closing quote of one string and the opening string of another quote is also a "quoted string" to this expression.
My suggestion is therefore to extract all quoted strings from your target using a simple
"[^"]*"
pattern, and then evaluate each match for the word(s) you want to disallow.试试这个
Try this