[英]Getting an array of matches and plain strings from a JavaScript regular expression
[英]Generating strings from regular expression in JavaScript
我認為可以通過使用蠻力生成字符串然后嘗試將它們與提供的正則表達式匹配並在匹配時打印來完成。
但是有沒有更好的方法來做到這一點?
正則表達式用於測試字符串是否與模式匹配。 我知道這一點。 我認為這樣做會很有趣。
console.log(new RandExp(/^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}$/).gen()); console.log(new RandExp(/^[0-9]{4}$/).gen()); console.log(new RandExp(/^[0-9,AZ]{4}$/).gen()); console.log(new RandExp(/^([AZ]){5}([0-9]){4}([AZ]){1}$/).gen());
<script src="https://github.com/fent/randexp.js/releases/download/v0.4.3/randexp.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.