项目地址
安装
使用
随机字符语法
支持大部分正则表达式的匹配语法
重复打印语法
与正则表达式的重复匹配语法相同
其他语法
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
|
public class MainTest {
@Test
public void test() throws RegexpIllegalException, UninitializedException, TypeNotMatchException {
random("\\w{6,12}@[a-z0-9]{3}\\.(com|cn)", "邮箱");
random("1(3|5|7|8)\\d{9}", "手机号");
random("-?[1-9]\\d*\\.\\d+", "浮点数");
random("https?://[\\w-]+(\\.[\\w-]+){1,2}(/[\\w-]{3,6}){0,2}(\\?[\\w_]{4,6}=[\\w_]{4,6}(&[\\w_]{4,6}=[\\w_]{4,6}){0,2})?", "网址");
}
private void random(String expression, String title)
throws RegexpIllegalException, TypeNotMatchException, UninitializedException {
System.out.println(title + " " + expression);
Node node = new OrdinaryNode(expression);
Pattern pattern = Pattern.compile(node.getExpression());
for (int i = 0; i < 10; i++) {
String data = node.random();
System.out.println("[" + pattern.matcher(data).matches() + "] " + data);
}
System.out.println();
}
}
|
输出
邮箱 \w{6,12}@[a-z0-9]{3}\.(com|cn)
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]手机号 1(3|5|7|8)\d{9}
[true] 18263364656
[true] 17539493178
[true] 17452542895
[true] 15190699623
[true] 13441385631
[true] 15450856416
[true] 18651247283
[true] 13835809899
[true] 18595798569
[true] 17115703866浮点数 -?[1-9]\d*\.\d+
[true] 8148340336.1501586550282701
[true] -3339660539.406
[true] -51.6120243661611419
[true] -731621835440468.9708278
[true] -27438753435.9137579
[true] 393811376.777268751417
[true] 3286498432415.3962664603
[true] -5299652275.9
[true] 216.93676279820770
[true] 34.36843273网址 https?://[\w-]+(\.[\w-]+){1,2}(/[\w-]{3,6}){0,2}(\?[\w_]{4,6}=[\w_]{4,6}(&[\w_]{4,6}=[\w_]{4,6}){0,2})?
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]
[true]