in reply to Re^2: How to determine if string contains non-ASCII characters ?
in thread How to determine if string contains non-ASCII characters ?
Your solution checks if any characters aren't ASCII.
my $is_ascii = $string !~ /[^\x00-\x7F]/;
An alternative is to check that all characters are ASCII.
my $is_ascii = $string =~ /^[\x00-\x7F]*\z/;
Both are fine. The first can be faster if the result is false, but the difference is probably inconsequential in practice.
|
|---|