in reply to Changing case inside substitution
Get YAPE::Regex::Explain from cpan.my $input = q' \cite[page 6]{Dickens} \cite[page 9]{Dickens} '; $input =~ s< \\cite \[ ( [^\]]+ ) # $1 \] { ( # $2 [a-zA-Z]+ ) } >" \\cite[$1]{\l$2} "gx; print $input; __END__ \cite[page 6]{dickens} \cite[page 9]{dickens} use YAPE::Regex::Explain; die YAPE::Regex::Explain->new(qr< \\cite \[ ( [^\]]+ ) # $1 \] { ( # $2 [a-zA-Z]+ ) } >x)->explain; __END__ The regular expression: (?x-ims: \\cite \[ ( [^\]]+ ) # $1 \] { ( # $2 [a-zA-Z]+ ) } ) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?x-ims: group, but do not capture (disregarding whitespace and comments) (case-sensitive) (with ^ and $ matching normally) (with . not matching \n): ---------------------------------------------------------------------- \\ '\' ---------------------------------------------------------------------- cite 'cite' ---------------------------------------------------------------------- \[ '[' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^\]]+ any character except: '\]' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \] ']' ---------------------------------------------------------------------- { '{' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- [a-zA-Z]+ any character of: 'a' to 'z', 'A' to 'Z' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- } '}' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Changing case inside substitution
by skillet-thief (Friar) on Sep 27, 2003 at 14:33 UTC |