79093210

Date: 2024-10-16 08:48:42
Score: 0.5
Natty:
Report link

In opposite to @Brock Adams' solution, I would recommend using (this will let You omit for instance russian characters):

/^[\s\p{Latin}]+$/u

instead of:

/^[\s\p{L}]+$/u

Generally, with this You can most of time omit situations of using solutions like (@Yuri Gor suggested):

[AaĄąBbCcĆćDdEeĘęFfGgHhIiJjKkLlŁłMmNnŃńOoÓóPpRrSsŚśTtUuWwYyZzŹźŻż]

that of course will work without a problem (for Polish chars).

This is well described in Unicode Regular Expressions, in particular in the Unicode Scripts section. And what is important as well, as in PHP Provides Three Sets of Regular Expression Functions - The preg Function Set section, if You'd like to use it with PHP:

A special option is the /u which turns on the Unicode matching mode, instead of the default 8-bit matching mode. You should specify /u for regular expressions that use \x{FFFF}, \X or \p{L} to match Unicode characters, graphemes, properties or scripts. PHP will interpret '/regex/u' as a UTF-8 string rather than as an ASCII string.

You can also use Unicode Blocks if You know, which characters range You'd like to use in Your code, and remember that:

Not all Unicode regex engines use the same syntax to match Unicode blocks.

But bare in mind, that there is no 100% working solution. Everything should be prepared individually.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Brock
  • Low reputation (1):
Posted by: elvisef