in reply to Can I change \s?

\s is suppose to match U+00A0 and sometimes does. It's a bug in Perl that cannot be fixed for backwards compatibility reasons. You can indicate you want the fix using feature unicode_strings. In earlier versions of Perl, you can also work around the bug by upgrading the string's internal format.

use strict; use warnings; use feature qw( say ); my $string = chr(160); no feature qw( unicode_strings ); say $string =~ /^\s*$/ ? 1 : 0 ; # 0 use feature qw( unicode_strings ); say $string =~ /^\s*$/ ? 1 : 0; # 1 no feature qw( unicode_strings ); utf8::upgrade($string); say $string =~ /^\s*$/ ? 1 : 0; # 1

Replies are listed 'Best First'.
Re^2: Can I change \s?
by JavaFan (Canon) on Oct 28, 2011 at 23:17 UTC
    Note that the feature unicode_strings was introduced in 5.12, but to make \s match \xA0 on a non-utf-8 strings, you need 5.14:
    $ perl-5.14.2 -wE '$_ = chr 0xA0; say /\s/ || 0' 1 $ perl-5.12.2 -wE '$_ = chr 0xA0; say /\s/ || 0' 0
    The -E enables "use feature 'unicode_strings'".