Created
July 25, 2019 08:48
-
-
Save mreis1/6ee99d01ecc74585c1d51d0fb20cb465 to your computer and use it in GitHub Desktop.
JS RegExp Examples
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 str = 'FFA0000000'; // Our starting string where we want to remove all '00' | |
var reg = /[0]{2,2}$/; | |
var match = reg.exec(str); | |
while(match = reg.exec(str)){ | |
var x = str.split(''); | |
x.splice(match.index,2); | |
str = x.join(''); | |
console.log(str, match) | |
} | |
// Loop 1: FFA00000 ["00", index: 8, input: "FFA0000000", groups: undefined] | |
// Loop 2: FFA000 ["00", index: 6, input: "FFA00000", groups: undefined] | |
// Loop 3: FFA0 ["00", index: 4, input: "FFA000", groups: undefined] | |
Result: FFA0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment