Update: And to think, I actually even tested the code! As ChemBoy said yesterday (I must not have been listening), "Test both cases before speaking." Fortunately, someone pointed out the error of my ways. The answer given below is entirely wrong ... at least, the substitution part of it, it would seem. Here's me saying "I really haven't figured it out yet." If I do before someone else gets in, I'll post my results here for everyone to see, along with my shame, below.

RIGHT ANSWER:
Heh heh <blush> and it was so easy, too ... In an RE, | refers to alternate matches. Strangely, you can capture the zero-width assertion end-of-line or a '--' at the end of the line just as shown. This RE finds the arbitrary characters followed by a space or a space-dash-dash at the end of the line; either case is a match, and either the null string or the dash-dash is captured in $1.

WRONG ANSWER:
I will admit right up front that the RE looks very strange to me, also ... perhaps japhy or a similar REMaster can sort out exactly what this is supposed to do. However, $ is only a "positional anchor" when used as the last character in the regex. Otherwise, it indicates variable substitution in the normal double-quote method. Thus, the first thing the parentheses capture is the character matching whatever $| is set to ($| is the autoflush flag, BTW), followed by two dashes at the end of the line. On my system, $| is normally set to '' (empty string), but it could be set to 1 if autoflush has been enabled using the typical Perl idiom $|++;. Again, I have no idea why you might want to do such a thing, except as an Obfu, of course!


-HZ

In reply to Re: Weird? regex Question by HyperZonk
in thread Weird? regex Question by Intrepid

Title:
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, details, 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, summary, 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.