Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: question : regex

by johngg (Canon)
on Oct 11, 2007 at 10:20 UTC ( #644179=note: print w/replies, xml ) Need Help??


in reply to question : regex

I'm not sure if I've understood your requirement as I can't tell where the 'g' comes from in your output. However, this should get rid of any 'X_' occurances after a '__'.

use strict; use warnings; my @strings = qw{ KHI0339B__P_H_Vita_Korangi_Ind_A HGW6120A__S_Popalzai_Cross_A }; my $rxPatt = qr{(?<=__)[A-Z]_}; foreach my $string ( @strings ) { print qq{Original: $string\n}; $string =~ s{$rxPatt}{} while $string =~ $rxPatt; print qq{Modified: $string\n\n}; }

The output is

Original: KHI0339B__P_H_Vita_Korangi_Ind_A Modified: KHI0339B__Vita_Korangi_Ind_A Original: HGW6120A__S_Popalzai_Cross_A Modified: HGW6120A__Popalzai_Cross_A

I hope this is of use.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://644179]
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: (4)
As of 2020-10-31 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (287 votes). Check out past polls.

    Notices?