in reply to Re: Special Variables in Regular Expression
in thread Special Variables in Regular Expression
use warnings; use strict; use YAPE::Regex::Explain; my $re = '<container><a>(.+?)<\/a><b>(.+?)<\/b><\/container>(<\?query\ +?>)??'; print YAPE::Regex::Explain->new($re)->explain;
produces this output:
The regular expression: (?-imsx:<container><a>(.+?)<\/a><b>(.+?)<\/b><\/container>(<\?query\?> +)??) 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): ---------------------------------------------------------------------- <container><a> '<container><a>' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .+? any character except \n (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- < '<' ---------------------------------------------------------------------- \/ '/' ---------------------------------------------------------------------- a><b> 'a><b>' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- .+? any character except \n (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- < '<' ---------------------------------------------------------------------- \/ '/' ---------------------------------------------------------------------- b>< 'b><' ---------------------------------------------------------------------- \/ '/' ---------------------------------------------------------------------- container> 'container>' ---------------------------------------------------------------------- ( group and capture to \3 (optional (matching the least amount possible)): ---------------------------------------------------------------------- < '<' ---------------------------------------------------------------------- \? '?' ---------------------------------------------------------------------- query 'query' ---------------------------------------------------------------------- \? '?' ---------------------------------------------------------------------- > '>' ---------------------------------------------------------------------- )?? 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 grouping ----------------------------------------------------------------------
While helpful, I still did not grok the ?? usage :(
|
|---|