llanato
llanato

Reputation: 2503

Regex pattern to allow foreign language characters using UTF-8

I have the below pattern in a PHP script that works grand:

define("PATTERN", "|^['0-9a-zA-Z\\\/\[\]\(\)\=\>\,\'\~\-\^\@\$\%\*\&\?\:\;\_\.\€\+\|\^\@\%\s" . '"' . "]{0,50}$|");

I'm trying to allow accented characters in other languages by using the \p{L} option but any strings still fail the pattern.

define("PATTERN", "|^['0-9\p{L}\\\/\[\]\(\)\=\>\,\'\~\-\^\@\$\%\*\&\?\:\;\_\.\€\+\|\^\@\%\s" . '"' . "]{0,50}$|");

Any online regex tester I use says something along the lines of:

No match groups were extracted.

This means that your pattern matches but there were no (capturing (groups)) in it that matched anything in the subject string.

Online example: https://regex101.com/r/nV4yC5/1

Is there a way to allow foreign language characters using UTF-8?

Upvotes: 1

Views: 961

Answers (1)

Halayem Anis
Halayem Anis

Reputation: 7805

try with this :

|^['0-9\p{L}\\\/\[\]\(\)\=\>\,\'\~\-\^\@\$\%\*\&\?\:\;\_\.\€\+\|\^\@\%\s" . '"' . "]{0,50}$|u

Upvotes: 1

Related Questions