-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChallenge_25.java
38 lines (31 loc) · 972 Bytes
/
Challenge_25.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package challenge21_30;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Regular expressions
* * 0 or more
* + 1 or more
* ? 0 or 1
* . any character
*
*/
public class Challenge_25 {
public static void main( String[] args ) {
testRegex("lisa@gmail.com");
testRegex("misterburns$gmail9net.com");
testRegex("homer07_simpson@hotmail*com");
testRegex("barney@???????{com");
testRegex("@&lenny%com");
testRegex("flanders@duff.");
}
static void testRegex(final String msg){
final String pattern = "^[A-Z0-9]*[@|$][&]?[a-z0-9]+.[a-z]{2,6}$";
final Pattern compiledPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
final Matcher matcher = compiledPattern.matcher(msg);
if (matcher.find()){
System.out.println("Founded value "+ matcher.group(0));
}else {
System.out.println("No match");
}
}
}