Removing spaces: Unicode properties - character classes
perl, regex
Solution
Yes.
$ diff -U0 \
<( unichars -au '\p{Space}' ) \
<( unichars -au '[\h\v]' ) \
&& echo No differences
No differences
Contrast with
$ diff -U0 \
<( unichars -au '\p{Space}' ) \
<( unichars -au '\s' ) \
&& echo No differences
--- /dev/fd/63 2012-07-20 11:28:33.356934588 -0400
+++ /dev/fd/62 2012-07-20 11:28:33.356934588 -0400
@@ -3 +2,0 @@
- ---- U+0000B LINE TABULATION
`\s` might start including U+000B soon, though.
`unichars` is installed by Unicode::Tussle.
Note: Without `/u` or `use 5.012;`, `\s` sometimes doesn't match NBSP.
I just found a bug in Perl (5.16.0). Reporting it immediately.
$ perl -le'print "\xA0" =~ /\p{Space}/ ?1:0'
1
$ perl -le'print "\xA0" =~ /\s/ ?1:0'
0
$ perl -le'print "\xA0" =~ /\s/u ?1:0'
1
__
$ perl -le'print "\xA0" =~ /\h/ ?1:0' \
1 \
> huh??
$ perl -le'print "\xA0" =~ /[\h]/ ?1:0' /
0 __/
$ perl -le'print "\xA0" =~ /[\h]/u ?1:0'
1
So that means, no, `\p{Space}` and `[\h\v]` are only equivalent if `/u` or `use 5.012;` is used.
Ticket #114220
Status:
- `/\h/` is equivalent to `/[\h]/` in 5.10, 5.12, 5.14 and 5.18
- `/\h/` is not equivalent to `/[\h]/` in 5.16.0
- Don't know about 5.16.1
Problem
Do these two substitutions always yield the same results? ``` $data =~ s/\p{Space}//g; $data =~ s/[\h\v]//g; ```