4 ms·
No, alpha doesn't work, at least in "grep -P" with "ru_RU.UTF-8" locale: $ echo Test | grep -oP '[[:alpha:]]+' Test $ echo Артём | grep -oP '[[:alpha:]]+
by tryauuum 6y ago
No, alpha doesn't work, at least in "grep -P" with "ru_RU.UTF-8" locale:
$ echo Test | grep -oP '[[:alpha:]]+'
Test
$ echo Артём | grep -oP '[[:alpha:]]+'
$ echo Артём | grep -oP '[А-Яа-я]+'
Арт
м
This thing works, though I've never seen one in the wild:
$ echo Артём | grep -oP '[\p{Cyrillic}]+'
Артём
- wruza 6y agoStandard classes only work for 8-bit locales, afaik, and also in some languages (e.g. perl) when a string encoding corresponds to an internal representation of what its engine thinks it is a "current" unicode format for the specific version of language and a checkout location. The fact that different tools stick to different engines, modes and normalization rules (bre/ere/posix/nfd/nfc/perl/pcre/php/ruby/icu/whatever) doesn't help either. Full cross-platform unicode matching is a can of worms that you usually don't want to open. It is basically CSV of the encoding world. /\S+?/ to the rescue. https://regular-expressions.mobi/unicode.html https://regular-expressions.mobi/unicode.html https://regular-expressions.mobi/refunicode.html https://regular-expressions.mobi/refunicode.html https://regular-expressions.mobi/posixbrackets.html https://regular-expressions.mobi/posixbrackets.html
- mikepurvis 6y agoWell, that is horrifying. TIL.
- drran 6y ago$ echo Артём | grep -oE '[[:alpha:]]+' Артём
- tryauuum 6y agoYep, -E vs. -P