Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: help required for regexp

by AnomalousMonk (Chancellor)
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'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942339]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-07-21 19:25 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (334 votes). Check out past polls.