Javascript examples for RegExp:Match Number
Replace number after underscore using regex and replace method
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w . j a v a 2 s . c o m*/ var starter = "first_23 another-thing_3 testTest_1 __3 __e"; var specialVal = "SPECIAL"; var re = /(_)(\d+)/g; var replaced = starter.replace(re, function (match, p1) { return p1 + specialVal; }); console.log(replaced); } </script> </head> <body> </body> </html>