There is a string str in which the user may be mentioned (for example, @username ).
I need to find out if there is a mention and, if there is one, frame it <span> .
|
1 answer
Here's an option:
var str = 'this is text with @thisUsername in it, and @theOther username'; $('#stringBefore').html(str); str = str.replace(/(@\w+)/gm, "<span>$1</span>"); $('#stringAfter').html(str); span { color: red; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Before: <div id="stringBefore"></div> After: <div id="stringAfter"></div> - Thank you for what you need! - ilyaspark
|
usernameformat? say spaces, characters? - cyadvert