Last active
March 20, 2020 13:29
-
-
Save azeezat/2e0fce9c84fa12add080a50b7f7fdfbe to your computer and use it in GitHub Desktop.
Regex in Java
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
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import java.util.ArrayList; | |
import java.util.List; | |
class RegexExample | |
{ | |
public static void main(String args[]) | |
{ | |
//An array list to create a list of emails | |
List emails = new ArrayList(); | |
emails.add("[email protected]"); | |
emails.add("[email protected]"); | |
emails.add("raheem.azeezat@venturegardengroupcom"); | |
//Invalid emails | |
emails.add("raheemazeezat#venturegardengroup.com"); | |
emails.add("@venturegardengroup.com"); | |
String regex = "^(.+)@(.+)$"; | |
Pattern pattern = Pattern.compile(regex); | |
for(String email : emails){ | |
Matcher matcher = pattern.matcher(email); | |
System.out.println(email +" : "+ matcher.matches()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment