当前位置: 移动技术网 > IT编程>开发语言>正则 > asp.net(c#) 使用Rex正则来生成字符串数组的代码

asp.net(c#) 使用Rex正则来生成字符串数组的代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
看这儿.如果你熟悉正则表达式 ,让我们进入正题.这个tool的名称叫regular expression exploration. 你可以从这儿 .目前的版本是1.0
看.如果你熟悉正则表达式

,让我们进入正题.这个tool的名称叫regular expression exploration. 你可以从这儿 .目前的版本是1.0 release. rex是一个命令行工具,

具体用法可以在cmd下执行便可以看到用法,这个是.net的程序.我们可以引用它,然后用下面的code来生成我们想要的字符串数组.

复制代码 代码如下:

/// <summary>
/// generates the test.
/// </summary>
/// <remarks>author petter liu http://wintersun.cnblogs.com </remarks>
[test]
public void generatetest()
{
string regex = @"^1(3[4-9]|5[012789]|8[78])\d{8}$";
rexsettings settings = new rexsettings(regex) { k = 10, encoding = characterencoding.ascii};
var results = rexengine.generatemembers(settings);
foreach (var result in results)
{
console.writeline(result);
}
}

输出:

18897190518
18889349691
18792280668
18831202949
15789824598
15998890392
13709912389
18779992048
13967892889
15928882992

这里我们使用的是手机号码的正则表达式.设置生成数是10,编码ascii.还有很多选项.可以看它的成员.这些字符串数据用来做什么就看你的了.

author: petter liu

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网