Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: help required for regexp

by AnomalousMonk (Abbot)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-10-01 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (386 votes), past polls