in reply to Long regexp un multiple lines

Another good place to look for use of the /x modifier is in perlretut. That said the same functionality as in the above stated regular expression could be written more tersely as:
/^(?:[\da-f]{2}:){5}[/da-f]{2}$/
or with /x
/^(?: [/da-f]{2}: ){5} [/da-f]{2} $ /x
or even shorter if you use qr.
$x = qr/[\da-f]{2}/;
(and later on)
/^(?:$x:){5}$x$/;

-enlil

Replies are listed 'Best First'.
Re: Re: Long regexp un multiple lines
by japhy (Canon) on Apr 22, 2004 at 18:19 UTC
    Enlil (et. al.), one of the convenient things about qr// is that it returns a self-contained regex. That means your "later on" code can be /^$x{5}$x$/ It seems weird to me that there's no simpler way to say "pattern X, N times, with pattern Y in between"... you have to write /^(?:XY){N-1}X$/. I wonder if there's something in Regexp::Common for that.
    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
      Actually the reason he had to use the (?:$x:){5} approach is because of the colon character that's supposed to delimit each grouping. Your solution leaves that out entirely. Yours will expand to:
      /^(?:[\da-f]{2}){5}(?:[\da-f]{2})$/
      ...note the missing : colons.


      Dave

        Oh, oops, duh.
        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;