randexp.js JavaScript 随机字符串库开源项目

我要开发同款
匿名用户2015年09月01日
59阅读
开发技术JavaScriptTypeScript
所属分类常用JavaScript包、Web应用开发
授权协议MIT

作品详情

randexp.js能帮助你生成符合某个正则表达式的随机字符串。

实现此库的动机:

正则表达式被用于每种语言,每位程序员都熟悉它们。正则表达式可以被轻易地用于表达复杂的字符串。而randexp.js能根据正则表达式,生成随机字符串。这是你想得到某种符合正则表达式的字符串的更好方式。

var RandExp = require('randexp');// supports grouping and pipingnew RandExp(/hello+ (world|to you)/).gen();// => hellooooooooooooooooooo world// sets and ranges and referencesnew RandExp(/<([a-z]\w{0,20})>foo<\1>/).gen();// => <m5xhdg>foo<m5xhdg>// wildcardnew RandExp(/random stuff: .+/).gen();// => random stuff: l3m;Hf9XYbI [YPaxV>U*4-_F!WXQh9>;rH3i l!8.zoh?[utt1OWFQrE ^~8zEQm]~tK// ignore casenew RandExp(/xxx xtreme dragon warrior xxx/i).gen();// => xxx xtReME dRAGON warRiOR xXX// dynamic regexp shortcutnew RandExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i');// is the same asnew RandExp(new RegExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i'));///If you're only going to use gen() once with a regexp and want slightly shorter syntax for itvar randexp = require('randexp').randexp;randexp(/[1-6]/); // 4randexp('great|good( job)?|excellent'); // great/// If you miss the old syntaxrequire('randexp').sugar();/yes|no|maybe|i don't know/.gen(); // maybe
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论