Mega Code Archive

 
Categories / JavaScript DHTML / Development
 

Regular Expression Switch

<html> <head> <title>Regular Expression Switch</title> </head> <body> <script type="text/javascript"> var rgExp = /(\w*)-*(\w*)/ var str = "AAAA--BBBB"; var resultStrng = str.replace(rgExp,"$2-$1"); document.writeln(resultStrng); </script> </body> </html>