Javascript examples for RegExp:Property
Using Regex with global attribute
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//w w w. j a va 2s . c o m var o = { bob : 'test is cool', steve : 'is not test test' }; retString = '[BOB] [STEVE] [BOB]'; for (n in o) { pattern = new RegExp('\\[' + n.toUpperCase() + '\\]', 'g'); retString = retString.replace(pattern, o[n].toString()); } console.log(retString); }); </script> </head> <body> </body> </html>