javascript - Regex with substitution around a number -
i have problem in substitution in javascript (html).
i need substitute tags around every number, e.g.
<1>
become:
<sub>1</sub>
or
<20>
become
<sub>20</sub>
etc.
how can do? thank much!
you can use replace
, regex
groups achieve this:
var text = '<1>blabla<20>'; var newtext = text.replace(/<(\d+)>/g, '<sub>$1</sub>'); console.log(newtext);
Comments
Post a Comment