Created
September 18, 2024 19:10
-
-
Save wilyJ80/69ea5487feee12bfcd74ab0574f105fb to your computer and use it in GitHub Desktop.
js multiline regex with comments?
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
const pattern = new RegExp([ | |
'\\d{3}', // Area code | |
'\\s*', // Optional whitespace | |
'-?', // Optional dash | |
'\\d{4}' // Main number | |
].join(''), 'g'); | |
const match = '123 4567'.match(pattern); | |
console.log(match[0]); // "123 4567" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment