I came across the 'hackerrank.com' website, and I thought it was a cool idea. I began running the practice examples in the REGEX section. I got stuck on one of them, stymied, and wrote to support asking what was going on, because my code was processing the data and returning the correct results locally, yet I was getting 'Wrong Answer' as the result when I submitted it for review.

When they replied, they suggested I go to www.regexr.com to see what the 'error' was, and pasting my expression in their simulator showed an error which wasn't coming up in my code on my Ubuntu 18 machine running Perl 5.26. In order to fix it, I modified the expression from  /([\w\.]+\@[\w]+\.[\w]+.*?)[^\w\.]/g to /([\w\.]+\@[\w]+\.[\w]+.*?)(?:$|[^\w\.])/g (explicitly looking for EOL as well).

Is this a version issue? Did some previous version of Perl not look at EOL as a non-word, and now it does?

And why did it match EOL on every line prior to EOD, but only Perl understood EOD to be a non-word? Why did I have to look for EOL so that I could match EOD?


In reply to hackerrank.com question by writch

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.