从正则表达式生成随机数据
项目地址
https://github.com/github-laziji/reverse-regexp
安装
git clone https://github.com/github-laziji/reverse-regexp.git cd reverse-regexp mvn install
<dependency> <groupid>org.laziji.commons</groupid> <artifactid>reverse-regexp</artifactid> <version>1.0-snapshot</version> </dependency>
使用
随机字符语法
支持大部分正则表达式的匹配语法
重复打印语法
与正则表达式的重复匹配语法相同
其他语法
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] 19cz8eisna@9je.com
[true] xpv3wj@i3h.cn
[true] 6qdufy@1g9.com
[true] ivnzsma373@6zd.cn
[true] i5wix97@ffe.cn
[true] mwqa5sxq@g8j.cn
[true] huxicem1y0w@j98.cn
[true] 1joqwself@u1o.cn
[true] _q4qtvxpemfh@bds.com
[true] 3xfh33aa@6lh.cn手机号 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] https://fumg-gafec.r2frrtlyx/ahg
[true] https://5phyvk9.wh7vl9z3aazvg.z-yqsimtdqw8s9-/wkcd
[true] https://t9dntbi.4su8vxyhcr6?t85gv=r6tytm&1c97x=nctya5
[true]
[true]
[true] https://by_is.tnlclavxmkuo.t90g5xetj/cqncgi
[true]
[true] https://huzmn.v-ltoy/dyl/peq?numt=__qdxg&8gby=wz8m&akkzl4=8nzfet
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
生成模型——NVAE: A Deep Hierarchical Variational Autoencoder——arxiv2020.07
Element-ui 表格 (Table) 组件中动态合并单元格
【leetcode C语言实现】剑指 Offer 19. 正则表达式匹配
Linux - 基础正则表达式、扩展正则表达式、grep使用正则表达式
网友评论