[Bioperl-l] A perl regex query

Chris Fields cjfields at uiuc.edu
Tue Sep 18 17:52:00 UTC 2007


On Sep 18, 2007, at 11:16 AM, bioperl-list at superfrink.net wrote:

> On Tue, 18 Sep 2007, Nathan Haigh wrote:
>
>> An even better way is to use the array as Spiros suggested, but you
>> should then be able to use that in the regex like this:
>>
>> my @ra_bad_terms = (  '-D-', 'Cyclic-' );
>> $string =~ s/@ra_bad_terms//g;
>
> I didn't know one could do that.  I couldn't get it to work so I asked
> around.  In case anyone else read it and thought about using that  
> code it
> might only work in Perl 6.
>
> Regards,
> Chad

I think the problem is what s/@terms//g means.  To most it means  
group substitutions, which you can get by using s/(?:a|b|c|d)//g; to  
others it means stepwise 's/$old//g for $old (@terms)'.

To go from an array of terms to an optimized group regex, use  
Regexp::List (CPAN to the rescue!):

http://search.cpan.org/~dankogai/Regexp-Optimizer-0.15/lib/Regexp/ 
List.pm

chris



More information about the Bioperl-l mailing list