I am trying to match a part of the string and it should be NOT case sensitive. I have the following code but I never get the replaced string.
var name = 'Mohammad Azam'
var result = name.replace('/' + searchText + '/gi', "<b>" + searchText + "</b>");
The searchText variable will be “moha” or “mo” or “moh”.
How can I get the matching thing in bold tags.
/pattern/ has meaning when it’s put in as a literal, not if you construct string like that. (I am not 100% sure on that.)
Try
EDIT:
Added the demo page for the above code.
Demo →
Code