-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregex.java
More file actions
38 lines (26 loc) · 931 Bytes
/
regex.java
File metadata and controls
38 lines (26 loc) · 931 Bytes
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 java_example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class regex {
public static void main(String[] args)
{
/*String email= "user@gmail.com";
String regex = "^(.+)@(.+)$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
System.out.println(email +" : "+ matcher.matches());*/
/* Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher("string1234more567string890");
while(m.find()) {
System.out.println(m.group());
}*/
String REGEX = "cls";
String INPUT = "welcome to the cls";
String REPLACE = "class";
Pattern p = Pattern.compile(REGEX);
//get a matcher object
Matcher m = p.matcher(INPUT);
INPUT = m.replaceAll(REPLACE);
System.out.println(INPUT);
}
}