-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexDemo.java
More file actions
57 lines (48 loc) · 1.26 KB
/
RegexDemo.java
File metadata and controls
57 lines (48 loc) · 1.26 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.regex;
/**
* @Author: lenovo
* @Date: 2020/2/2 21:46
* @Description:
*
* 详情参见:https://www.cnblogs.com/expiator/p/12250598.html
*/
public class RegexDemo {
public static void regex1(){
String str="abcdddabc";
String regex=".*d+.*";
if (str.matches(regex)){
System.out.println(true);
}
}
public static void regex2(){
String str="abcdefg";
String regex=".*efg";
if (str.matches(regex)){
System.out.println(true);
}
}
public static void regex3(){
String str="a";
String regex="\\w";
if (str.matches(regex)) {
System.out.println(true);
}
}
public static void regex4(){
String str="abdf1459";
String regex="[a-z]{4}[1-9]{4}";
if (str.matches(regex)) {
System.out.println(true);
}
}
public static void regex6(){
String str="catdog";
String regex="^cat$";
String regex2="^cat.*";
String regex3=".*dog$";
boolean isMatch1=str.matches(regex);
boolean isMatch2=str.matches(regex2);
boolean isMatch3=str.matches(regex3);
System.out.println(isMatch1+","+isMatch2+","+isMatch3);
}
}