Search code examples
regexzend-frameworkzend-framework3zend-route

regular Expression alphnummeric with some spaces


to avoid downvoting, I tried everything in this post: regular expression to allow spaces between words

I use RexEx in combination with ZF3 routing.

at the moment my expression looks like follows:

'id'     => '[a-zA-Z0-9 ]*',

it accepts alphanumeric without spaces. I will have string combination for example:

34011111X000000ABC is accepted normaly this "number" would look like this:

3401 1111 X 0000 00 is not accepted by RegEx

sometimes there might be a "/" or a "-" inside

I also read some tutorials and tried different combinations, nothing worked. so may be Zend doesn't accept all expressions? Any help appreciated


Solution

  • You can't have spaces in URLs. They will get converted to %20 (or possibly +), neither of which will match your regular expression, so that's why it doesn't work.

    I would suggest you rethink your URL scheme if you can - convert any spaces to dashes (or similar) beforehand to make things a bit more readable.