I need a JavaScript regex to wrap "#hashtags" with <span>
tags
Example:
Before: "I need #help, please. #Thanks"
After: "I need <span>
#help</span>
, please. <span>
#Thanks</span>
"
Currently, /#\w*\b/g
finds all of the #hashtags but how do I wrap them in span tags?
Thanks!
This works -
str = "I need #help, please. #Thanks"
str = str.replace(/(\#[a-zA-Z0-9\-\_]+)/g,"<span>$1</span>");
//> "I need <span>#help</span>, please. <span>#Thanks</span>"
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