I am using PCRE in PHP and I need to find a way to generate say an array of all possible matching 开发者_如何学编程values. Any ideas?
For example if I had R[2-9]{1}
I would want:
R2
R3
R4
R5
R6
R7
R8
R9
PCRE does not have the ability to generate sample strings based on a regular expression. I do not know of a PHP library that does. Libraries that can do this usually support only limited regex flavors and need artificial restrictions for regexes like R[2-9]*
that can match an infinite number of strings.
If you only need to do this for very simple regexes like R[2-9]
then it shouldn't be to hard to either:
- Parse the regex in your own code to generate the sample values, or to use another mechanism.
- Or to use your own mechanism to specify "R followed by a digit between 2 and 9" from which your code can then generate both the regex and the list of sample values.
- Or, if the regexes are hard-coded in your source code, just to type out the list of values by hand.
精彩评论