Last active
November 2, 2018 09:57
-
-
Save aal89/eba0891c64841ae4046b7b50dfb0e7be to your computer and use it in GitHub Desktop.
A Javascript regex to filter all dutch cellphone numbers from a particular text and filter for uniqueness. Works for no mathces, one match and multiple matches.
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 text = ` | |
the text containing a couple of 0612345678 numbers. like so: 0612345678 and so: | |
0687654321 | |
and | |
another | |
example | |
0674839201 | |
`; | |
// Approach one: returns an ES6 Set. | |
new Set(text.match(/06[0-9]{8}/gm)); //=> Set(3) {"0612345678", "0687654321", "0674839201"} | |
// Approach two: returns an array only containing unique values. | |
(text.match(/06[0-9]{8}/gm) || []).filter((e,i,a) => a.indexOf(e) == i); //=> ["0612345678", "0687654321", "0674839201"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shell approach to getting unique cellphone numbers from any file (here a
.log
file), sorted and filtered for unique ones.