javascript - Regular expression for inserting span tags -
i need regular expression replacement of string below wrapper format.
example input:
c# regular expression combination of space, alpha , special-character. delta
output:
<span>c# <span>regular <span>expression <span>for <span>combination <span>of </span><span>space<span>,</span> </span><span>alpha </span><span>and </span><span>special</span><span>-</span><span>character</span>. </span><span>also </span><span>for </span><span>delta</span>
you use replace
call:
var txt = "c# regular expression combination of space, alpha , special-character. delta"; var result = txt.replace(/[\w#]+\s*|[^\w#]+\s*/g, "<span>$&</span>\n"); console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Comments
Post a Comment