0

I've been having a small problem in regex in production. I know this is so very simple, but I was annoyed by this issue.

All I need is to allow "ñÑ" string to save in my database. This is all working in my Local, the problem is when I deployed to production its not working anymore.

OS Server: Ubuntu
regex used: "/^[a-zA-ZÑñ0-9\s-]+$/"

Did anyone encounter this? Is there any setup or I need to install in the Ubuntu Server? Please help. Thanks.

----------------------------------------------------------------

Update: I added a modifier u to my regex: regex used: "/^[a-zA-ZÑñ0-9\s-]+$/u"

And I get this error:

invalid UTF-8 string at offset 11
kwingkwingko
  • 791
  • 7
  • 23
  • 2
    Use `"/^[a-zA-ZÑñ0-9\s-]+$/u"` – Wiktor Stribiżew Feb 21 '19 at 08:16
  • Hi @WiktorStribiżew, appreciate your quick answer. I've already done that. I forgot to include in my question that I'm using a Latin1 not UTF-8. So when I add the modifier "/u" to my regex. Message: preg_match(): Compilation failed: invalid UTF-8 string at offset 11 – kwingkwingko Feb 21 '19 at 08:20
  • I already did change from Latin to UTF-8. But, I still get the same error. I already checked the char-set in Ubuntu Server and it was using UTF-8. – kwingkwingko Feb 21 '19 at 08:56
  • Try `\x{XXXXX}` notation, `"/^[a-zA-Z0-9\x{D1}\x{F1}\s-]+$/u"` – Wiktor Stribiżew Feb 21 '19 at 08:57
  • Also, see https://stackoverflow.com/questions/10037336/pcre-is-compiled-without-utf-support – Wiktor Stribiżew Feb 21 '19 at 08:59
  • @WiktorStribiżew, this works for me "/^[a-zA-Z0-9\x{D1}\x{F1}\s-]+$/u". What I thought earlier, every time I add the modifier I will always get this error "invalid UTF-8 string at offset 11". But now it's working.. Can you explain what just happen? Thank you very much. – kwingkwingko Feb 21 '19 at 09:18
  • I changed the close link at the top to the exact dupe now. If you also need explanation, it is [here, by Casimir](https://stackoverflow.com/a/37336400/3832970). – Wiktor Stribiżew Feb 21 '19 at 09:27
  • Thanks you very much.. – kwingkwingko Feb 21 '19 at 09:40

0 Answers0