replace - Regex - Select words that are not in span with class -


i have following js -

var pattern = new regexp("(\\b" + value + "\\b)", 'gi') if (pattern.test(text)) {     text = text.replace(pattern, "<span class='class1'>$1</span>"); }  (e.g. value = 'text', text = 'simple text <span class='class1'>simple text</span> text.') 

with js wrapp 'text' words span tag. in case have second 'text' word double wrapped span tag. need replace words equal value variable if word in span class1 need skip word.

example: initial text was: "when using alternative, order important since matching algorithm attempt match leftmost alternative first.". need wrap 'using alternatives' , 'alternatives' words. first replace 'using alternatives', result be:

"when <span class="class1">using alternative</span>, order important since matching algorithm attempt match leftmost alternative first." 

then replace "alternative":

"when <span class="class1">using <span class="class1">alternative</span></span>, order important since matching algorithm attempt match leftmost <span class="class1">alternative</span> first.". 

so have first "alternative" wrapped 2 span tags. , not need second tag "alternative", enough have 'using alternative'.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -