Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
First, quantifiers inside character classes are not seen as quantifiers, but rather, as literal characters to become a part of the character class. Put your * quantifier outside of the character class if that's what you intend.

Next, [\S\W] means anything that's either a non-space character, or a non-word character (usually A-Za-z_). Well, just about everything is either a non-space or a non-word. In fact, since there is no overlap between \s and \w, you've just wiped out the entire line (especially with the /g modifier). Every character I can think of would either fit the "not space" or the "not word" catagory, and thus, every character is wiped out.

The second expression is a negated character class. You still need to get rid of those * quantifiers inside of the square brackets. The negated character class is saying any character that is not either a space or a word. That's different. The only characters that are neither space nor word, are things like comma, quote, (and many others).

So where your first regex matches everything, and substitutes it with nothing (thus wiping out the string), the second regex matches just characters that are neither space nor word, and substitutes those characters with nothing, leaving you with spaces and words.


In reply to Re: ^\s not equal \S? by davido
in thread ^\s not equal \S? by SavannahLion

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (7)
    As of 2021-01-26 06:48 GMT
    Find Nodes?
      Voting Booth?