Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Last active August 29, 2015 14:15
Show Gist options
  • Save dmnugent80/f144fa1e7be704e3fc19 to your computer and use it in GitHub Desktop.
Save dmnugent80/f144fa1e7be704e3fc19 to your computer and use it in GitHub Desktop.
Regex phone numbers and emails
//emails:
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b
//phone numbers:
\(?\d{3}\)?-? *\d{3}-? *\d{4}
String s = "*** [email protected]&&^ [email protected]((& ";
Matcher m = Pattern.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z0-9-.]+").matcher(s);
while (m.find()) {
System.out.println(m.group());
}
String s = "give11arrow123test2356read809cell1245cable1257give222...";
String[] parts = s.split("(?<=\\d)(?=\\D)");
System.out.println(Arrays.toString(parts));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment