[Bioperl-l] A perl regex query

Nathan Haigh n.haigh at sheffield.ac.uk
Tue Sep 18 11:44:14 UTC 2007


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;

Again you might need escaping with \Q and \E - can't remember off hand.

You might also want to look here:
http://www.perl.com/pub/a/2002/06/04/apo5.html?page=15

Cheers
Nath



Spiros Denaxas wrote:
> Heya, seperate the items you want to remove by a pipe and add the g
> regex flag. For example:
>
> spiros$ echo Cyclic-2,3-bisphospho-D-glycerate | perl -ne ' $_ =~
> s at -D-|Cyclic\-@@g ; print $_ ;'
> 2,3-bisphosphoglycerate
>
> IMHO this is ugly. Best to make an array of all the elements you want
> to remove and then iterate through the array, calling the regex each
> time with a different element. This way it will be much more easy to
> read, debug and maintain.
>
> For example
>
> my $ra_bad_terms = [  '-D-', 'Cyclic-' ] ;
>
> foreach (@$ra_bad_terms) {
>    $string =~ s@$_@@g ;
> }
>
> etc.
>
> Dont forget escaping and \Q \E if needed.
>
> Spiros
>
>
>
> On 9/18/07, neeti somaiya <neetisomaiya at gmail.com> wrote:
>   
>> Hi,
>>
>> This isnt really a bioperl query.
>> But does anyone know how I can substitute all special characters (+ some
>> other things) in a string with nothing in perl?
>> I mean if I have a string like Cyclic-2,3-bisphospho-D-glycerate and I want
>> ouput as bisphosphoglycerate. I want to remove -D-, Cyclic-, 2,3- etc.
>>
>> --
>> -Neeti
>> Even my blood says, B positive
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>
>>     
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>   




More information about the Bioperl-l mailing list