Created
October 17, 2014 09:31
-
-
Save icodesido/b8380ce129ccdb296eac to your computer and use it in GitHub Desktop.
Use a regex with placeholders to reverse name and surname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(\w+)\s(\w+)/; | |
var str = "John Smith"; | |
var newstr = str.replace(re, "$2, $1"); | |
console.log(newstr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment