javascript - How to find partial occurrence of a word in a string and replace the whole word -


i want find partial occurrence of word in string , attach <span> around it.

more in detail, want find occurrences of words starting percentage sign "%" (for example %mystring) , replace them <span>%mystring<span>.

i found similar solutions in php, i'm not sure how go in javascript.

try this:

str = 'go %link not %link'; replacedstr = str.replace(/\s\%(.*?)(\s|$)/g, ' <span>%$1</span>$2'); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -