Created
November 28, 2019 07:17
-
-
Save dwaps/5fcfc7add9fd979b6607782a443a53d7 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
const mail = "cocojaco@mail.fr"; | |
const regex = new RegExp("^(\\w+)@(\\w+\\.\\w{2,4})$"); | |
const mailOK = regex.test(mail); | |
const groups = regex.exec(mail); | |
const localPart = groups[1]; | |
const domainPart = groups[2]; | |
// ES6: email | |
const [ , local, domain ] = regex.exec(mail); | |
// ES6: American date format to Fr format | |
const [ , m, d, y ] = /(\d{2})-(\d{2})-(\d{4})/.exec("11-02-2017"); | |
console.log(`${d}/${m}/${y}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment