Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: regex pattern match problem

by Polyglot (Pilgrim)
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.



Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://786208]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-01-18 08:45 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (208 votes). Check out past polls.