0

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

pia-sophie
  • 505
  • 4
  • 21
  • 1
    Try `'(*UCP)[a-zA-Z0-9\s]*'` or `'(*UTF)(*UCP)[a-zA-Z0-9\s]*'`, maybe your input contains Unicode whitespace. – Wiktor Stribiżew Nov 08 '17 at 08:58
  • it is both not accepted. Warning: preg_match(): Compilation failed: (*VERB) not recognized or malformed at offset 64 – pia-sophie Nov 08 '17 at 09:21
  • 1
    That is what I call *very* weird. At least the `UCP` verb is quite uniform across PCRE implementations. `UTF` may look as `UTF8`, `UTD16`, or `UTF32`. However, it seems the main issue is not the regex, although if partial matches are accepted, you need `^[a-zA-Z0-9 ]*$`. – Wiktor Stribiżew Nov 08 '17 at 09:23
  • yes I also think it is a zend-issue, perhaps it doesn't accept spaces for routing at all. Anyway your new suggestion doesn't work also either for the string without spaces – pia-sophie Nov 08 '17 at 09:27

1 Answers1

1

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.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69