Created
August 3, 2018 00:10
-
-
Save rain-1/a8d1bb04ad01ebe6a4ac68fa33f7961c to your computer and use it in GitHub Desktop.
multirex
This file contains 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 text = "foobar"; | |
text = text.replace(/o/g, "a"); | |
text = text.replace(/a/g, "x"); | |
document.write(text); | |
var text = "foobar"; | |
var re1 = /o/g; | |
var re2 = /a/g; | |
text = text.replace(re1, "a"); | |
text = text.replace(re2, "x"); | |
document.write(text); | |
var text = "foobar"; | |
var re1 = /o/; | |
var re2 = /a/; | |
var re = new RegExp(re1.source + "|" + re2.source, "g"); | |
function repl(m) { | |
if(m.match(re1)) { | |
return m.replace(re1, "a") | |
} | |
if(m.match(re2)) { | |
return m.replace(re2, "x") | |
} | |
} | |
text = text.replace(re, repl); | |
document.write(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment