main
parent
d05bf19923
commit
a5b0c71856
@ -1,13 +1,21 @@
|
|||||||
package UnitTest;
|
package UnitTest;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TestRegex {
|
public class TestRegex {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//1、是否匹配
|
String text = "应用心理学(6000元/年;以上体检要求,录取时以高考体检表为准)";
|
||||||
String content="应用心理学(6000元/年;色盲、色弱者,不予录取.以上体检要求,录取时以高考体检表为准)";
|
String regex = ".*?\\(\\d+元/年;.*?\\)";
|
||||||
String pattern=".*(6000元/年.*)";
|
|
||||||
boolean isMatch = Pattern.matches(pattern, content);
|
Pattern pattern = Pattern.compile(regex);
|
||||||
System.out.println(isMatch);
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
System.out.println("匹配成功!");
|
||||||
|
System.out.println(matcher.group(0));
|
||||||
|
} else {
|
||||||
|
System.out.println("匹配失败!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue