Back to top

Matching accented letters and other fun stuff in PHP regular expressions like preg_match

I recently had to validate that input text included only letters, apostrophes and spaces including various accented characters. This was surprisingly tough for me to figure out in PHP.

Some good resources:

Ultimately what worked for me:


$string = "this is a name' éñƃɹǝƃ";
if (preg_match("/^[ \'\p{L}]+$/iu", $string)) {
print 'matched, dog';
}
else {
print 'did not match, dog';
}

People Involved: