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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -