in reply to Regex - backreferencing multiple matches in one group.

Each () can only capture one thing; if it's repeated, the $<digit> variable gets whatever was captured last.

Since there are only at most 4, try:

$temp_=~ /\!(\S+?) #tablename \[(.*?)\] #table variables (?:\[(.*?)\] (?:\[(.*?)\] (?:\[(.*?)\])?)?)? \s+.*/x; #white space then rest of text. print Dumper ($1, $2, $3, $4, $5);

Replies are listed 'Best First'.
Re^2: Regex - backreferencing multiple matches in one group.
by Anonymous Monk on Mar 05, 2008 at 18:05 UTC
    A couple minor suggestions:
    Nesting is not needed.
    The "\s+.*" at the end does nothing.
    /\!(\S+?) #tablename \[(.*?)\] #table variables (?:\[(.*?)\])? (?:\[(.*?)\])? (?:\[(.*?)\])? /x
      Nesting is not needed, but more clearly indicates the up-to-4.

      The +.* I grant you, but the \s does do something.