Inparablog

A comparative genomics and bioinformatics blog

  • Home
  • About
  • Perl
    • Arrays
    • RegExp
  • Links
  • Photos
  • Contact
RSS

Retrieving an unknown number of backreferences

Posted on July 28, 2008 by John
No commentsLeave a comment

I have been racking my brains over this, but could not find help anywhere. It seems that doing wacky stuff in Perl out of desperation actually pays off!

I wanted to search a string using this regexp without knowing how many matches I would find:

$string =~ /\(\d+):/g

This would match ’15′  and ’20′ in a string which looks like this :

$string = "(yeast:0.12313,((zebrafish:0.12312,fugu:0.84134)15:0.52313,
human:0.94424)20:0.93313);";

One can access the found values by using backreferences (in this case $1 and $2). But what if you do not know how many backreferences there are?

This piece of perl code will return the values of all the backreferences:

my @array;
while ($string =~ /\)(\d+):/g) {
push @array, $1;
}

@array will contain the values of all the backreferences. Don’t ask me why this works…

Categories: Perl | Tags: Backreferences, Regexp, Regular Expressions

About John

I am a Post-Doc at St. Radboud University Medical Center (NL). My research involves bioinformatics and comparative genomics on cilia and signal transduction pathways.
View all posts by John→
Can a biologist fix a radio?
Protein complex evolution and network rewiring

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*


question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Search

  • The author

    Gravatar My name is John van Dam and I am a Post-Doc at St. Radboud University Medical Center (NL). My research involves bioinformatics and comparative genomics on cilia and signal transduction pathways.
  • About me

    • LinkedIn Profile
    • Mendeley Profile
    • Research Blogging Profile
  • Bioinformatics Blogs

    • Bioinformatics
    • Bioinformatics Zen
    • Fisheye Perspective
    • nodalpoint
    • Omics! Omics!
    • Public Rambling
    • The Tree of Life
    • What You’re Doing Is Rather Desperate
    • YOKOFAKUN
  • Perl

    • Beginning Perl
    • Bio::Perl
    • PerlMonks
  • Tags

    Backreferences BBC Conference Cordyceps E-values Fungus Hardware Homology Insects Lightning Mac OS Meiosis Office paradox permalinks PhD Phylogenetic tree phylogeny Python Quadrupel radio Regexp Regular Expressions research Review software Thunder Trappist tree Upgrade Weather Westvleteren Westvleteren 12 Wordpress Youtube
  • Copyright notice

    Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
    Creative Commons Licentie
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
© Inparablog. Proudly Powered by WordPress | Nest Theme by YChong