Last active
January 8, 2018 04:02
-
-
Save fent/1439081 to your computer and use it in GitHub Desktop.
randexp examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RandExp = require('randexp'); // must require on node | |
// supports grouping and piping | |
new RandExp(/hello+ (world|to you)/).gen(); | |
// => hellooooooooooooooooooo world | |
// custom character sets and ranges and references | |
new RandExp(/<([a-z]\w{0,20})>foo<\1>/).gen(); | |
// => <m5xhdg>foo<m5xhdg> | |
// wildcard | |
new RandExp(/random stuff: .+/).gen(); | |
// => random stuff: 湐箻ໜ䫴㳸長���邓蕲뤀쑡篷皇硬剈궦佔칗븛뀃匫鴔事좍ﯣ⭼ꝏ䭍詳蒂䥂뽭 | |
// ignore case | |
new RandExp(/xxx xtreme dragon warrior xxx/i).gen(); | |
// => xxx xtReME dRAGON warRiOR xXX | |
// dynamic regexp shortcut | |
new RandExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i'); | |
// is the same as | |
new RandExp(new RegExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment