jjmerelo
jjmerelo

Reputation: 23537

Including non-breaking whitespace in character classes

In Perl6, no-break space is considered space, so

say 'Perl 6' ~~ /   /   # Please understand there's a no-break space in the middle

produces

Null regex not allowed

Solution is to quote the character, like so

say 'Perl 6' ~~ / ' ' / ; # OUTPUT: «「 」␤»

However, that does not work if you want to include a non-breaking space into a character class:

$str ~~ /<[ & < > " ' {   ]>/ )

I could use Zs, which is a space separator, but that one seems more broad... Any other way? Quoting does not help, either. Question is, what character class should I use there?

Upvotes: 10

Views: 208

Answers (1)

mscha
mscha

Reputation: 6840

Try:

$str ~~ /<[ & < > " ' { \xA0 ]>/

or more readable:

$str ~~ /<[ & < > " ' { \c[NO-BREAK SPACE] ]>/

Upvotes: 12

Related Questions