[Bioperl-l] A perl regex query

Spiros Denaxas spiros at lokku.com
Tue Sep 18 06:57:18 EDT 2007


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
>


More information about the Bioperl-l mailing list