Reputation: 253
I need to write a JavaScript RegEx that matches only the partial strings in a word.
For example if I search using the string 'atta'
it should return
true for khatta
true for attari
true for navrattan
false for atta
I am not able to figure how to get this done using one RegEx. Thanks!
Upvotes: 4
Views: 19654
Reputation: 11751
You want to use a non-word boundary \B
here.
/\Batta|atta\B/
Upvotes: 9
Reputation: 15196
sp00m almost got it right
^(atta.+|.+atta|.+atta.+)$
If whitespace is not allowed you could write
^(atta[\S]+|[\S]+atta|[\S]+atta[\S]+)$
Upvotes: 2