I want to turn a string str = "hello, my name is \"michael\", what's your's?" into "hello, my name is <span class="name">michael</span>
How can I do that in javascript? I know how to do str replace, but how do I get the content that I selected/replaced with it.
Thanks!!!
str = "hello, my name is \"michael\", my friend's is \"bob\". what's yours?";
str.replace(/"([^"]+)"/g, '<span class="name">$1</span>');
Outputs:
hello, my name is <span class="name">michael</span>, my friend's is <span class="name">bob</span>. what's your's?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With