use warnings; use strict; use YAPE::Regex::Explain; my $re = '[\w().-]*\(?([\w.-])?\)?\s*->\s$'; print YAPE::Regex::Explain->new($re)->explain(); __END__ #### The regular expression: (?-imsx:[\w().-]*\(?([\w.-])?\)?\s*->\s$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- [\w().-]* any character of: word characters (a-z, A- Z, 0-9, _), '(', ')', '.', '-' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \(? '(' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \1 (optional (matching the most amount possible)): ---------------------------------------------------------------------- [\w.-] any character of: word characters (a-z, A-Z, 0-9, _), '.', '-' ---------------------------------------------------------------------- )? end of \1 (NOTE: because you're using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \1) ---------------------------------------------------------------------- \)? ')' (optional (matching the most amount possible)) ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- -> '->' ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------