Mehta, Perdeep wrote:

> Hi All,
> 
> I'm beginner to pattern matching in Perl and was writing a code to parse a
> string. I tried pretty hard to extract the words that are of interest from a
> string but had no luck.
> 
> Here is all-in-one-line string that I want to parse:
> $string = "biological process|mitosis|IEA|GO:0007067|MGD|na|biological
> process|cell cycle|IEA|GO:0007049|MGD|na|cellular
> component|intracellular|IEA|GO:0005622|MGD|na|molecular function|protein
> tyrosine phosphatase|IEA|GO:0004725|MGD|na|biological process|M phase of
> mitotic cell cycle|IEA|GO:0000087|MGD|na|biological process|protein amino
> acid dephosphorylation|IEA|GO:0006470|MGD|na";
> 
> I want to extract recursively all words delimited by two pipes ( | ) that
> follow a specific pattern like "process" or "component". For example, I want
> mitosis, cell cycle, M phase of mitotic cell cycles, and protein amino acid
> dephosphorylation, extracted that are associated with the pattern "process".
> I tried several combinations of the following code but it gets only one word
> or everything or nothing at all.
> 
> while ($string  =~  /process(\S+(?!\|)(\s\S+)*)/g) { 
>    print "\tbiological process\t$1\n"; 
> }
> 
> Correction to this code or an alternative suggestion is highly appreciated.


This should handle the situation above:


while ($string  =~  /process\s*\|([^|]+)\|/g) {
        print "\tbiological process\t$1\n";
}

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to