http://qs321.pair.com?node_id=416545


in reply to Regular expressions and accents

If you're using locales (which you probably are, if you're dealing with accented characters), Perl's regular expression system is smart enough (usually) to include those accented characters in the \w metacharacter class. You can use this to your advantage. Here's what you need to match:

Any character that is not a nonword character, that is not a-z or A-Z nor a numeric digit, nor underscore. That's a mouthful, but here's how it's written:

print "$character\n" if $character =~ m/[^\Wa-zA-Z\d_]/;

That looks a little ugly, so here's a POSIX version that looks cleaner:

print "$character\n" if $character =~ m/[^[:^alpha:]a-zA-Z]/;

These solutions are not thoroughly tested, as I'm currently sitting at an older operating system that doesn't have much in the way of locale support.


Dave