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!
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!
Share Improve this question asked May 28, 2014 at 9:41 maurya8888maurya8888 2531 gold badge4 silver badges11 bronze badges 02 Answers
Reset to default 9You want to use a non-word boundary \B
here.
/\Batta|atta\B/
sp00m almost got it right
^(atta.+|.+atta|.+atta.+)$
Fiddle.
If whitespace is not allowed you could write
^(atta[\S]+|[\S]+atta|[\S]+atta[\S]+)$