|
|
| more useful options | |
| PerlMonks |
Re: How to remove other language character from a stringby moritz (Cardinal) |
| on Nov 26, 2012 at 05:27 UTC ( #1005554=note: print w/ replies, xml ) | Need Help?? |
|
You need to use utf8; to tell Perl that your source file is in UTF-8. That way non-ASCII literal strings work the way you want them to.
use strict;
use warnings;
use 5.010;
use utf8;
binmode STDOUT, ':encoding(UTF-8)';
my $str = "ครัวซองเเซนด์วิชไข่ดาว Croissant Egg Sandwich ครัวซองเเซนด์วิชไข่ดาว";
$str =~ s/[^\p{Latin}\p{Common}]//g;
$str =~ s/^\s+|\s+$//g;
say $str;
__END__
Croissant Egg Sandwich
See also: Character Encodings in Perl. Updated to unlinkify the brackets, and to exclude \p{Common} instead of \s from removal.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||