Regular expression for all letters

On a multilingual site, you need to check one field for the correctness of the entered data. The string must contain only letters. How to capture Russian, German, French, English and Spanish with a regular expression?

/^[^\W]+$/i – doesn’t work.

UTF-8 encoding.

PHP5


Answer 1, authority 100%

  1. Need u
  2. modifier

  3. /^(?>\pL\pM*)+$/u

  • \pLwill match any letter: c, w, á
  • \pM*will match any number of modifiers – this is necessary because the letter á can be written as one character, and can be written as two: á.

Answer 2

I solved for many languages ​​like this:

$lang[] = ‘abcgdeejzyklmn…heyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy arec are’

$lang[] = ‘abcde…ßABCDE…’;

$lang[]…

preg_ match_all(‘/[a-zA-Z’.implode(”, $lang).’]/is’, $str, $out);

And this is the only scheme that worked with a bang, in all the others there were jambs with the understanding of any symbols of the language.


Answer 3

There are filters in php, dig in this direction, the article was on Habré.
In fact, these are regular expressions wrapped in functions. Most likely there is a filter for letters.


Answer 4

As far as I understand, the problem is solved. So just after.

/^[^W]+$/i – doesn’t work.

It doesn’t seem like it should. This is either a search for strings from non-W, or not from Wand \.
[] must contain characters, ranges, or classes. I myself had nothing to do with php, but Google suggested:

POSIX Character Class Definitions
value
Meaning
[:digit:]
[:alnum:]
[:alpha:]
[:blank:]
[:xdigit:]
[:point:]
[:print:]
[:space:]
[:graph:]
[:upper:]
[:lower:]
[:cntrl:]