Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Regex for a partial string match only

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!

like image 325
maurya8888 Avatar asked Sep 02 '25 04:09

maurya8888


1 Answers

You want to use a non-word boundary \B here.

/\Batta|atta\B/
like image 134
Lee Kowalkowski Avatar answered Sep 04 '25 17:09

Lee Kowalkowski