regex - Only match if surrounded by quotes -


this question has answer here:

i need match words of criteria, only if within quotes*. i'd wish via regex.

i think there's "jquery plugin that". google jquery basic arithmetic plugin.

let's have above text subject of regex search, , i'd wish find word "plugin", if inside quotes. not need match second "plugin" word @ end of sentence, since it's not within quotes, (edit) need match multiple occurrences of "plugin", enclosed quotes (even if there multiple occurrences inside single quotation block).

with working expression, following words (highlighted bold text) should matched:

i think there's "jquery plugin that". google jquery basic arithmetic plugin.

i have theoretical solution use positive lookahead determine if there or odd number of quotes, , match word if number odd.

what regular expression should use accomplish this?

*double quotes only


i use expression match words not surrounded quotes, following similar logic:

\bplugin\b(?=[^"]*(?:"[^"]*"[^"]*)*$) 

you can use simple regex this:

".*?(plugin).*?" 

working demo

regular expression visualization


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -