Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: regex pattern match problem

by Polyglot (Monk)
on Aug 05, 2009 at 19:57 UTC ( #786208=note: print w/ replies, xml ) Need Help??


in reply to regex pattern match problem

It looks to me like you need to either preserve the original sentence and run a global substitution on it once for the sentence #1 output, and then run again with a non-global substitution for each of the other sentences, addressing each match one at a time; or else put a function in the replacement side of the substitution and do your processing within that function.

Blessings,

~Polyglot~


Comment on Re: regex pattern match problem
Re^2: regex pattern match problem
by newbio (Beadle) on Aug 05, 2009 at 20:49 UTC
    Yes, Polyglot, that's what I want. Could you please elaborate on your suggestion. How do I perform the non-global substitutions for their corresponding positions? It is possible that exactly the same pattern may get repeated in a sentence, so their positions need to be taken into account, possibly using substr function. Still, I cannot figure out how that works. I tried to do something like this but it does not work.

    $string=$line="Input sentence"; if ($line =~ /\*\*([^\*]+)\*\*\s(kinase|isoform|protein|peptide|li +gand)\s\$\$([^\$]+)\$\$\s[\(\,]\s\*\*([^\*]+)\*\*\s[\)\,]/) { print "yes"; while ($line =~ /(\*\*([^\*]+)\*\*\s(kinase|isoform|protein|pe +ptide|ligand)\s\$\$([^\$]+)\$\$\s[\(\,]\s\*\*([^\*]+)\*\*\s[\)\,])/g) + { $pattern=$1; $string =~ s/(\*\*([^\*]+)\*\*\s(kinase|isoform|protein|pe +ptide|ligand)\s\$\$([^\$]+)\$\$\s[\(\,]\s\*\*([^\*]+)\*\*\s[\)\,])/pq +rstuv/; $string =~ s/\*\*//g; $string =~ s/\$\$//g; $string =~ s/p +qrstuv/$pattern/; print WF "$string\n"; $string=$line; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://786208]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-10-25 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls