简体   繁体   中英

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?

试试这个:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM