[Bioperl-l] module for pattern matching

Andreas Kahari ak at ebi.ac.uk
Fri Apr 30 04:00:17 EDT 2004


On Fri, Apr 30, 2004 at 10:47:55AM +0530, gowthaman ramasamy wrote:
> hello list,
> i would like to know if there is any module for the following purpose.
> 
> using perl i want to capture the multiple occurrence of a pattern (reg
> exp) ,which i can do by following line.
> @array1 = $string =~ m/..../;
> But how can i get the position of all the occurrences of pattern?. If i
> have 10 matches, i want not only the matches but also their positions. 
> Any help will be appreciated.
> gowtham

Example:

    $str = "aabbaabbaabbaabb";
    while ($str =~ /aa/g) {
	print pos($str), "\n";
    }

Result:

2
6
10
14


Read more about the pos() function ("perldoc -f pos").


Cheers,
Andreas

-- 
|[  ]| Andreas Kähäri      EMBL, European Bioinformatics Institute
| ][ |                     Wellcome Trust Genome Campus
|[  ]| Ensembl Developer   Hinxton, Cambridgeshire, CB10 1SD
| ][ | DAS Project Leader  United Kingdom


More information about the Bioperl-l mailing list