Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a double-negative:</p> <pre><code>/[^\S\n]/ </code></pre> <p>To avoid platform differences <a href="http://perldoc.perl.org/perlport.html#Newlines" rel="noreferrer">warned about in perlport</a> regarding mappings of <code>\r</code> and <code>\n</code>:</p> <pre><code>/[^\S\x0a\x0d]/ </code></pre> <p>That is, not-not-whitespace or not-newline and similar for the pattern that excludes CR and NL.</p> <p>Distributing the outer not (<em>i.e.</em>, the complementing <code>^</code> in the character class) with <a href="http://en.wikipedia.org/wiki/De_Morgan&#39;s_laws" rel="noreferrer">De Morgan's law</a>, this is equivalent to “whitespace and not carriage return and not newline,” but don't take my word for it:</p> <pre><code>#! /usr/bin/env perl use strict; use warnings; use 5.005; # for qr// my $ws_not_nl = qr/[^\S\x0a\x0d]/; for (' ', '\f', '\t', '\r', '\n') { my $qq = qq["$_"]; printf "%-4s =&gt; %s\n", $qq, (eval $qq) =~ $ws_not_nl ? "match" : "no match"; } </code></pre> <p>Output:</p> <pre>" " => match "\f" => match "\t" => match "\r" => no match "\n" => no match</pre> <p>Note the exclusion of vertical tab, but this is <a href="http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace" rel="noreferrer">addressed in v5.18</a>.</p> <p>This trick is also handy for matching alphabetic characters. Remember that <code>\w</code> matches “word characters,” alphabetic characters but <em>also</em> digits and underscore. We ugly-Americans sometimes want to write it as, say,</p> <pre><code>if (/^[A-Za-z]+$/) { ... } </code></pre> <p>but a double-negative character-class can respect the locale:</p> <pre><code>if (/^[^\W\d_]+$/) { ... } </code></pre> <p>That is a bit opaque, so a POSIX character-class may be better at expressing the intent</p> <pre><code>if (/^[[:alpha:]]+$/) { ... } </code></pre> <p>or as <a href="https://stackoverflow.com/users/415428/szbalint">szbalint</a> suggested</p> <pre><code>if (/^\p{Letter}+$/) { ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload