> I added some /i flags to the numeric patterns.

please note you can also use qr//x to make the sub-terms more readable

> I was surprised that I had to escape the slashes

Well Quote-like-Operators can chose the delimiter freely.

like qr~~ or qr{}

> I used your suggestions

Well ... mainly AI suggestions ;-)

Some were good, others not to my taste.

TIMTOWTDI ...

Here my take

{ my $HEX = qr/ [0-9A-F] /xi; my $HEX_X = qr/ [0-9A-FX] /xi; my $H_opt = qr/ [h]? /xi; my $INT = qr/ \b INT \s? $HEX{2} [hH]? /x; # is longer $H_opt + better ??? our $hyperlinkpattern = qr~ ... $INT ... ~x; }

Please note how the helper variables are restricted to the scope and how $HEX{2} is NOT interpreted as a hash-lookup (surprised me!).

Hope my suggestions helped you having better maintainable code :-)

There are many more improvements which come to mind but I'm prone to over-engineering and it's in you're in a better position to decide what works best for you =)

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery


In reply to Re^4: Reusing a complex regexp in multiple spots, escaping the regexp by LanX
in thread Reusing a complex regexp in multiple spots, escaping the regexp by ecm

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.