php - Match alpha letters and accented alpha letters -
php - Match alpha letters and accented alpha letters -
i'm looking regex code pattern:
must contain @ to the lowest degree 1 of next , match whole string.
can contain alpha letters (a-z a-z) ...
and accented alpha letters (á ä à etc).
i'm using preg_match('/^([\p{l}]*)$/iu', $input), \p{l} matches unicode letters, including chinese. want allow english language alphabet letters accented variants of them.
so johndoe, fübar, lòrem, fírstnäme, Çákë valid inputs, because contain @ to the lowest degree 1 alpha letter and/or accented alpha letters, , whole string matches.
i suggest compact regex:
(?i)(?:(?![×Þß÷þø])[a-zÀ-ÿ])+ see demo.
this regex takes advantage of fact accented letters want seem live in unicode character rangeÀ ÿ (see table), add together character class. the À-ÿ has few unwanted characters. unlike engines, pcre (php's regex engine) not back upwards character class subtraction, mimic negative lookahead (?![×Þß÷þø]) be aware characters such à can expressed several unicode code points (the à grapheme, or a grave accent). match non-combined graphemes. catching variations hard. in code:
$regex = "~(?i)(?:(?![×Þß÷þø])[a-zÀ-ÿ])+~u"; $hit = preg_match($regex,$subject,$match); php regex unicode
Comments
Post a Comment