Match every Quoted String that DOES NOT contain a substring
M开发者_JS百科ultiline 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!
My initial answer is to need to apply the negative lookahead every time the dot matches, like so:
\"((?!hello).)*?\"
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
\"((?!hello).)*?\"
精彩评论