Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: help required for regexp

by AnomalousMonk (Canon)
on Dec 07, 2011 at 22:32 UTC ( #942339=note: print w/ replies, xml ) Need Help??

in reply to help required for regexp

I may be reading too much into the OP, but if upaksh wants to translate digit groups in strings like 'f3333_4444_2222' only when the prefix character is an 'f', the other solutions fail (as shown below). Here are a couple of approaches:

>perl -wMstrict -le "my %Hidlabels = ('3333' => '1', '4444' => '2', '2222' => '3'); my $t = 'f3333_4444_2222 g4444_2222_3333 f4444_2222_3333 f3333 _3333'; ;; my $s = $t; $s =~ s{ (\d+) }{$Hidlabels{$1}}xmsg; print qq{'$s'}; ;; $s = $t; $s =~ s{ (?: \G (?<! \A) _ | f) \K (\d+) }{$Hidlabels{$1}}xmsg; print qq{'$s'}; ;; $s = $t; my $f = qr{ f \d{4} (?: _ \d{4}){2} }xms; $s =~ s{ ($f) } { (my $x = $1) =~ s{(\d+)}{$Hidlabels{$1}}xmsg; $x; }xmsge; print qq{'$s'}; " 'f1_2_3 g2_3_1 f2_3_1 f1 _1' 'f1_2_3 g4444_2222_3333 f2_3_1 f1 _3333' 'f1_2_3 g4444_2222_3333 f2_3_1 f3333 _3333'

Comment on Re: help required for regexp
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942339]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2015-11-30 04:07 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (757 votes), past polls