Javascript examples for String Operation:String Replace
Find and replace value in a string via regex
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//w w w . j a v a 2 s . c o m str = "http://mydomanin.org/en/components#children-with-disablities"; var replace = { km:"en", en:"km" }; str = str.replace(/km|en/gi, function(match){ return replace[match]; }); console.log(str); } </script> </head> <body> </body> </html>