in reply to Changing case inside substitution

You need to quantify
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 ----------------------------------------------------------------------
Get YAPE::Regex::Explain from cpan.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Changing case inside substitution
by skillet-thief (Friar) on Sep 27, 2003 at 14:33 UTC
    Get YAPE::Regex::Explain from cpan.

    I will, that looks very useful. Thanks for the detailed explanation.

    It works now obviously, ;-) I was missing just some experience with the details of regex syntax, it looks like.

    s-t