loris has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
The following:
my $xpath = 'BoringNode[1]/InterestingNode[@InterestingAttribute="outg +rabe"]/AnotherBoringNode[@BoringAttribute="grey"]'; $xpath =~ /(InterestingNode\[.*?\])/; $1 =~ /"(.*)"/; print $1 . "\n";
does what I want, but I am sure that with backreferences I could do it in one step. However, my Googling hasn't helped me much. Can any one help me and/or point me to a really good RE tutorial on the web?
Update
Thinking about it (rather than some Googling for The Perfect RE Tutorial) makes me realise that I can do:
$xpath =~ /(InterestingNode\[@.*?"(.*?)".*?\])/; print $2 . "\n";
Any comments?
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting part of a substring with one regex (with backreference?)
by Samy_rio (Vicar) on Oct 28, 2005 at 08:52 UTC | |
by loris (Hermit) on Oct 28, 2005 at 09:20 UTC | |
by japhy (Canon) on Oct 28, 2005 at 13:01 UTC | |
by loris (Hermit) on Oct 28, 2005 at 13:12 UTC | |
by Util (Priest) on Oct 28, 2005 at 13:01 UTC | |
by loris (Hermit) on Oct 28, 2005 at 13:09 UTC |