Skip to content

Instantly share code, notes, and snippets.

@frankhu-2021
Created January 6, 2019 01:44
Show Gist options
  • Save frankhu-2021/c94ee5589f68416cc104d3dbe2efc9b5 to your computer and use it in GitHub Desktop.
Save frankhu-2021/c94ee5589f68416cc104d3dbe2efc9b5 to your computer and use it in GitHub Desktop.
Regex for Phone numbers
1. xxx-xxx-xxxx grep -o '[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}' file.txt
2. (xxx)xxx-xxxx grep -o '([0-9]\{3\})[0-9]\{3\}\-[0-9]\{4\}' file.txt
3. xxx xxx xxxx grep -o '[0-9]\{3\}\s[0-9]\{3\}\s[0-9]\{4\}' file.txt
4. xxxxxxxxxx grep -o '[0-9]\{10\}' file.txt
grep -o '\([0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}\)\|\(([0-9]\{3\})[0-9]\{3\}\-[0-9]\{4\}\)\|\([0-9]\{10\}\)\|\([0-9]\{3\}\s[0-9]\{3\}\s[0-9]\{4\}\)' file.txt
- Found online, and put on my git for reference.
Credit goes to Raullen Chai
on
http://stackoverflow.com/questions/2269586/grep-with-regex-for-phone-number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment