in reply to Re^2: This regular expression has me stumped
in thread This regular expression has me stumped
use warnings; use strict; use YAPE::Regex::Explain; my $re = 's!(?:^|/)[^\s,@;]*(?<=/)([^\s,@;]+?)(?=[\s,@;]|$)!$1!g'; my $parser = YAPE::Regex::Explain->new($re); print $parser->explain;
The regular expression: (?-imsx:s!(?:^|/)[^\s,@;]*(?<=/)([^\s,@;]+?)(?=[\s,@;]|$)!$1!g) 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): ---------------------------------------------------------------------- s! 's!' ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- / '/' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- [^\s,@;]* any character except: whitespace (\n, \r, \t, \f, and " "), ',', '@', ';' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- (?<= look behind to see if there is: ---------------------------------------------------------------------- / '/' ---------------------------------------------------------------------- ) end of look-behind ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^\s,@;]+? any character except: whitespace (\n, \r, \t, \f, and " "), ',', '@', ';' (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- (?= look ahead to see if there is: ---------------------------------------------------------------------- [\s,@;] any character of: whitespace (\n, \r, \t, \f, and " "), ',', '@', ';' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- ! '!' ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- 1!g '1!g' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
|
|---|