This is because a negative lookahead ((?!)) is a zero-width assertion, and doesn't capture anything, nor does it take up any space at all. That means that if the part isn't 'www.', it effectively is blank space so nothing will ever match there.

Try this, and go from there

/^https?:\/\/.*?\.?(?<!www\.)robidu\.de\//;

It checks for anything non-greedy up to an optional dot, but if what is prior to the domain name is "www.", it's a no match. This uses a negative lookbehind, which is also a zero-width assertion (same as a negative lookahead), but the difference is that it can see anything else there prior to the lookbehind.

With that said, if you're wanting to allow only certain names, you might consider something like this, instead of looking negatively:

my $r = 'https://forum.robidu.de/'; my @allowed = qw(ww2 forum); my $re = join('|', @allowed); print $r =~ /^https?:\/\/$re\.?robidu\.de\//;

-stevieb


In reply to Re: regexp: Mind-boggling negative assertions... by stevieb
in thread regexp: Mind-boggling negative assertions... by Robidu

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.