Javascript examples for String Operation:String Replace
Use regex to Replace word on the regex search result
<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 2s . co m*/ a = 'item a', b = 'item b', c = 'item c' string = '@a@ and @b@@c@ this is a test!', regex = /@(\w+?)@/g; console.log(string.replace(regex, function (match, group) { return window[group]; })); } </script> </head> <body> </body> </html>