Skip to content

Commit 7fb177e

Browse files
committed
update
1 parent f30d3df commit 7fb177e

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed
Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
11
package com.chen.api.util.regex;
22

3+
import org.junit.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
37
import java.util.regex.Matcher;
48
import java.util.regex.Pattern;
59

610
/**
7-
* 测试正则表达式类
11+
* 测试正则表达式类 (//http://blog.csdn.net/allwefantasy/article/details/3136570/)
812
*
913
* @author Chen WeiJie
1014
* @date 2017-11-16 21:31
1115
**/
1216
public class TestRegularExpression {
1317

1418

15-
//http://blog.csdn.net/allwefantasy/article/details/3136570/
16-
public static void main(String[] args) {
1719

18-
if (args.length < 2) {
19-
System.out.println("输入的字符串为空!");
20-
System.exit(0);
20+
@Test
21+
public void test1(){
22+
23+
String input = "This !! unusual use!!of exclamation!!points";
24+
25+
Pattern pattern =Pattern.compile("!!");
26+
String [] arr = pattern.split(input);
27+
StringBuffer sb = new StringBuffer();
28+
pattern.matcher(input).appendReplacement(sb,arr[0].toUpperCase()).appendTail(sb);
29+
30+
String stringSpit ="this is a String!";
31+
String[] arr2 = stringSpit.split("\\n");
32+
33+
}
34+
35+
36+
@Test
37+
public void test2() {
38+
39+
Matcher m = Pattern.compile("[frb][aiu][gx]").matcher("fix the rug with bags");
40+
41+
while (m.find()) {
42+
System.out.println(m.group());
2143
}
22-
System.out.println("输入的字符串为: \"" + args[0] + "\"");
23-
for (int i = 1; i < args.length; i++) {
24-
System.out.println("正则表达式为: \"" + args[i] + "\"");
25-
Pattern p = Pattern.compile(args[i]);
26-
Matcher m = p.matcher(args[0]);
27-
while (m.find()) {
28-
System.out.println("Match \"" + m.group() + "\" at positions " + m.start() + "-" + (m.end() - 1));
29-
}
44+
45+
m.reset("fix the rig with rags");
46+
47+
while (m.find()) {
48+
System.out.println(m.group());
3049
}
50+
51+
3152
}
3253

3354

55+
56+
57+
58+
3459
}

0 commit comments

Comments
 (0)