#!/usr/bin/perl -- use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( qr/^_*((\d*|#*|\**)+(\[\d+\-\d\])?)(X*\.?\!?)$/ )->explain; __END__ The regular expression: (?-imsx:^_*((\d*|#*|\**)+(\[\d+\-\d\])?)(X*\.?!?)$) 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): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- _* '_' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- ( group and capture to \2 (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- \d* digits (0-9) (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- #* '#' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \** '*' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- )+ end of \2 (NOTE: because you're using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \2) ---------------------------------------------------------------------- ( group and capture to \3 (optional (matching the most amount possible)): ---------------------------------------------------------------------- \[ '[' ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \- '-' ---------------------------------------------------------------------- \d digits (0-9) ---------------------------------------------------------------------- \] ']' ---------------------------------------------------------------------- )? end of \3 (NOTE: because you're using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \3) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ( group and capture to \4: ---------------------------------------------------------------------- X* 'X' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \.? '.' (optional (matching the most amount possible)) ---------------------------------------------------------------------- !? '!' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \4 ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------