I'm using the following javascript regexes to find a pattern in a string containing html.
sHTML = sHTML.replace(new RegExp("td>" + sFindPhrase + "[^\'\"\\\/\>\<]* ", "gi"), "<span id='spanFnd'></span><span style='background-color: orange'>$&######");
sHTML = sHTML.replace(new RegExp("[^\'\"\\\/\>\<]" + sFindPhrase + "[^\'\"\\\/\>\<]* ", "gi"), "<span id='spanFnd'></span><span style='background-color: orange'>$&######");
so if sHTML is:
<td>brou ha ha </td><td>John May lives </td><td> blablabla</td>
and the user has typed Jo shouldn't it match the whole John substring? But it matches John May. That is it goes to the second space character it finds in the string, it doesn't stop to the first. Why and how can I solve this ?
Thank you in advance.
For those who have downvoted my question: it doesn't matter if the string contains html or plain text. Even with plain text it still doesn't work as it should.