Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Need to modify my reg-expression

by flounder99 (Friar)
on Nov 06, 2003 at 20:57 UTC ( [id://305151]=note: print w/replies, xml ) Need Help??


in reply to Need to modify my reg-expression

If none of your text or explainations contain brackets you can skip all bracketed text.
use strict; my $line = " Jack and jill went up the hill to fetch a pail of water. +Jack fell down and broke his crown and jill came tumbling after."; my $newline = $line; # MAKE A COPY OF THE LINE my @wordlist = ('pail', 'water'); # THE LIST OF WORDS TO SEARCH FOR my %hash; $hash{water}{explanation} = 'A clear liquid.'; $hash{pail}{explanation} = 'A cylindrical vessel with a handle that ho +lds water.'; ## FOR EACH WORD IN THE WORDLIST -- FOOTNOTE THE WORD for (my $i=0; $i < @wordlist; $i++) { my $currword = $wordlist[$i]; $newline =~ s/((?:[^{}]*?|\{.*?\})*)(\b$currword(?:ed|ing|al)?\b)/$1$2 \\footn +ote \{$2: $hash{lc($2)}{explanation}\}/xi; } print $newline; __END__ Outputs: Jack and jill went up the hill to fetch a pail \footnote {pail: A cyl +indrical vessel with a handle that holds water.} of water \footnote { +water: A clear liquid.}. Jack fell down and broke his crown and jill +came tumbling after.

--

flounder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-23 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found