Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including non-breaking whitespace in character classes

Tags:

regex

raku

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?

like image 776
jjmerelo Avatar asked Jun 22 '18 17:06

jjmerelo


People also ask

What is non-breaking space character?

In word processing and digital typesetting, a non-breaking space, , also called NBSP, required space, hard space, or fixed space (though it is not of fixed width), is a space character that prevents an automatic line break at its position.

Which character entities name is used for non-breaking space?

A commonly used entity in HTML is the non-breaking space: &nbsp; A non-breaking space is a space that will not break into a new line.

Where do I put &NBSP?

Type &nbsp; where you want to insert an extra space. Add one non-breaking space character for every space you want to add. Unlike pressing the spacebar multiple times in your HTML code, typing &nbsp; more than once creates as many spaces as there are instances of &nbsp; .

How do you insert a nonbreaking space in HTML?

HTML Non-Breaking Space (&nbsp;) The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as &nbsp; or &#160;.


Video Answer


1 Answers

Try:

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

or more readable:

$str ~~ /<[ & < > " ' { \c[NO-BREAK SPACE] ]>/
like image 153
mscha Avatar answered Oct 11 '22 16:10

mscha