Generate a random string based on a regular expression

前端 未结 4 1988
走了就别回头了
走了就别回头了 2020-12-09 13:13

Is there any way of generating random text which satisfies provided regular expression.
I am looking for a function which works like below

var reg = So         


        
4条回答
  •  醉话见心
    2020-12-09 13:33

    I have seen fairly good solutions in perl and ruby on github, but I think there are technical issues that make a complete solution impossible. For example, /[0-9]+/ has an infinite upper bound, which is not practical for selecting random numbers from.

    Never seen it in JavaScript, but you could translate.


    EDIT: After googling for a few seconds... http://fent.github.com/randexp.js/

提交回复
热议问题