This should be a relatively simple question, but I've been completely unable to find an answer after much searching, so I apologize if the answer is obvious.

If I have a PCRE with a subpattern, for example:
/(\d\s+foo)/
I know that I can repeat that subpattern easily with reptition quantifiers, i.e.
/(\d\s+foo){1,3}/
and that I can force a repeat of what had been matched, even after intervening characters, like this:
/(\d\s+foo)[^\r\n]*\1/
however, I don't know if it's possible to repeat the conditions imposed by the subpattern (i.e. have a second occurance of the subpattern without spelling it all the way out). Is there a way of taking, say,
/(\d\s+foo)[^\r\n]*(\d\s+foo)/
and representing the second, identical subpattern with some symbol/metacharacter? I know that, in terms of pure functionality, such a distinction would be irrelevant, but frankly the redundancy wounds my sense of Perl beauty, and thus I'd prefer a cleaner, nicer way to do this. :-)

Also, if such a method does exist, is it equally valid for named subpatterns?

Thank You,
Alex Kirk

In reply to PCRE: Repeating Subpattens After Intervening Characters by schnarff

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.