regex - Regular Expression replacing keyword that occurred multiple times -


i tried match "text" word can replace , highlight "text" word, using..

strtext = "this triple text text texting word" keyword = " text " regex.replace(strtext, keyword, m=> string.format(" <span class='keywordhighlight'>{0}</span> "); 

the result : triple text text texting word

but first word highlighted, need space @ begin , end of "text" keyword avoid matching "texting",

anyone have idea how solve it?

use word boundaries:

regex.replace(@"\b"+strtext+"\b" ...); 

\b word boundary in regex. match text , not texting


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -