Rob Rob - 5 months ago 12
PHP Question

Convert regular expressions to readable text

Is there a way in PHP, that you can convert the following regular expression

3.[0123]


To

3.0, 3.1, 3.2, 3.3


Thank you for looking in to this :)

EDIT:
Sorry i was unclear :/
I want to read out XML, and show that on a web-page, and i want to show that to users.
In that XML, there is a regular expression like this one:

3.[0123]

My question is: Can I convert a regular expression like the one above me, to a readeble text that the average user understands :)

So that the user sees this: 3.1, 3.2, 3.3, ...

And not this: 3.[0123] (this is an example, it can be every number).

Answer

You can use the or to make the regex a bit more readable.

(3\.0|3\.1|3\.2|3\.3)

Also note the escaping of .. The . is a special character in regex and means "any character" your regex as is would have allowed more than just 3.0, 3.1, 3.2, or 3.3. You also should use anchors to ensure that is the only value in the string. So a final version (without delimiters):

^(3\.0|3\.1|3\.2|3\.3)$