in reply to Replacing text in a string
Can anyone tell me what is the problem in the above syntax.The first match is greedy (in Perl terms), it matches up to the terminating </fn> of the second footnote. Also, you don't want a "g" modifier at the end of the first match, since there should be only one "fn1" and only one "fn2", and you set $found to only one of them anyway.
With these two changes made in that one line, the code works ok. The revised line is
That takes care of your question and gets you on your way, but it's worth taking the time to work through Grandfather's code above, as you will learn some more advanced Perl techniques.$str =~ s/<fn id="fn$i">(.+?)<\/fn>//;
|
|---|