Javascript examples for RegExp:RegExp test
Using Regex to remove spaces between '[' and ']'
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w . j av a2s . c o m function replaceMe(string){ return string.replace(/\[.*?\]/g, function(string) { return string.replace(/\s/g, ''); }) } console.log(replaceMe("[first name] + [ last name ]")) console.log(replaceMe("[first name] + last name ]")) console.log(replaceMe("[first name] + last name ")) } </script> </head> <body> </body> </html>