I am working on Perl programs to parse XML and do regex string replacements on the data. I read a couple of articles on string substitution using Perl.
While replacing the source value with the target string they are using some $
variables($1
,$2
, $3
and $4
etc.). How does the pattern store the values while doing the string comparison?
Please find some sample code which am looking for.
Sample XML file
<Para>
<Hyperlink Display="hide" Protocol="http" URN="https://www.basicurl.org/oid/10.1161/RIA.0000abc">
AHA
</Hyperlink>
(Free)
</Para>
<Para>
<Hyperlink Display="hide" Protocol="http" URN="https://www.abcd.com">
Background: some text with multiple lines
</Hyperlink>
(i have three lines of code)
</Para>
</Comment>
Target achievement
$Str =~ s|<Hyperlink\b[^\>]*?>([^\xFF]*?)([12][890][0-9]{2})([^\xFF]*?)</Hyperlink>|<Emph Emph.Type="Italic">$1</Emph>$2$3|g;
To my understanding, we are selecting hyperlink data and replacing the value in $str
. The /g
represents a global substitution. What are the values of $1
, $2
, and $3
from the above input file?