-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternMatcherTest.java
More file actions
35 lines (25 loc) · 1.09 KB
/
PatternMatcherTest.java
File metadata and controls
35 lines (25 loc) · 1.09 KB
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
package devdojo.regex.test;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class PatternMatcherTest {
public static void main(String[] args) {
String regex = "([^A-Z#@!\\|\\*&:,])+@([a-z])+(\\.([a-z])+)+";
String text = "luffy@hotmail.com, 123jotaro@gmail.com, #@!zoro@mail.br, teste@gmail.com.br, sakura@mail ";
/* Esse método NÃO muda o elemento para que se enquadre no padrão */
String[] list = text.split(",");
Arrays.stream(list)
.filter(item -> item.matches(regex))
.forEach(item -> System.out.println(item.trim() + "🆗"));
/* Já esse, adapta o contéudo para que se enquadre no padrão */
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
System.out.println(matcher.pattern());
while (matcher.find()){
System.out.println(matcher.start() + " - " + matcher.group() + " - " + matcher.end());
}
String x = "gui";
x += " morais";
System.out.println(x);
}
}