To answer your second question first: you're doing a negative lookbehind (Horizon NOT preceeded by vertical).

perldoc perlre has this to say about negative lookbehind:

                 If you are looking for a "bar" that isn't preceded by a
                 "foo", "/(?!foo)bar/" will not do what you want.  That's
                 because the "(?!foo)" is just saying that the next thing can-
                 not be "foo"--and it's not, it's a "bar", so "foobar" will
                 match.  You would have to do something like "/(?!foo)...bar/"
                 for that.   We say "like" because there's the case of your
                 "bar" not having three characters before it.  You could cover
                 that this way: "/(?:(?!foo)...|^.{0,2})bar/".  Sometimes it's
                 still easier just to say:

                     if (/bar/ && $` !~ /foo$/)
As for your first regexp, first it appears to me that you are running it with /i, because I can't see how it could match otherwise. Also, you have too many fields that can appear once or never (the ? muliplier). That says to me that you are trying to fit too many different possibilities into one regular expression.

You should either break that regular expression into two or more, or find some text that is always there to 'anchor' the regexp engine.


In reply to Re: RegEx revision needed by matija
in thread RegEx revision needed by Anonymous Monk

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.