Match each string with quotes that does not contain a substring

Multi-line test string:

dkdkdkdk dkdkdkdk dkdkdkd dkdkdkd "hello" dkdkdkdkdk dkdkdk "goodbye.hello" dkdkdkd kdkdkd kdkdkdk "hello.goodbye.hello" dddd "test" ssss "http:xy.f/z/z" "" "." "http:/dkdkd/dkdkdk/dkdkdkdkdkdk.g" 

I want to match each line containing " hello "

This corresponds to each quoted line.

 \"(.+?)\" 

This corresponds to each quoted string containing hello in it.

 \"(.*?)hello(.*?)\" 

But this does not correspond to every quoted line that does NOT contain greetings.

 \"(.*?)(?!hello)(.*?)\" 

Thanks for any help!

+4
source share
2 answers

My initial answer is to apply a negative lookahead every time the point matches, for example:

 \"((?!hello).)*?\" 

However, there is a problem with this regular expression in targets that contain more than one quotation mark - the space between the final quote of one line and the input line of the other quote is also a "line quote" for this expression.

My suggestion is to extract all quoted lines from your target using a simple "[^"]*" pattern, and then evaluate each match for the words you want to ban.

+3
source

try it

 \"((?!hello).)*?\" 
0
source

All Articles