Flexer
Flexer

Reputation: 253

How to find strings that are enclosed in quotes and contain specific substring

I need to have a regex that finds strings in quotes and they also need to contain specific substring. For example the substring could be "joe".

"123joe456" -> true
123joe456 -> false
"joe" -> true
"1joe" -> true
"joe2" -> true
"jo2e" -> false

Help is appreciated. Thanks!

Upvotes: 0

Views: 51

Answers (3)

Gaurang Tandon
Gaurang Tandon

Reputation: 6753

This:

\".*(?<![a-z])(joe)(?![a-z]).*\"

Demo.

Will not match joe in "heyiamjoe"

Or if you don't want that, simply use ^\".*joe.*\"$

Upvotes: -1

Kamehameha
Kamehameha

Reputation: 5473

This should work -

^\".*?joe.*?\"$

Demo here

Upvotes: 0

aelor
aelor

Reputation: 11116

like this

^\"\w*(?=joe)\w*\"$

demo here : http://regex101.com/r/jA9hC5

Upvotes: 2

Related Questions