in reply to Re^4: Why XML not well formed?
in thread Why XML not well formed?
First, the parens in the pattern part of the regex collect the value we find, then the $1 in the replace puts it back in. In that respect the follwing regex would do nothing but spin cycles;
That said, the regex I posted would work only if no other entites existed. Take a look at the other regexs above, they do a better job of 'thinking' ahead, to prevent possible errors in the future.
Somebody could, and I have seen it done, place other entities in the url, such as:
Don
WHITEPAGES.COM | INC
So, in your regex the first set of parens save the & for later use. But you don't use it, instead you find all of the &s and replace them literaly with "(&)" including the parens.$line =~ s/(&)/$1/g;
That said, the regex I posted would work only if no other entites existed. Take a look at the other regexs above, they do a better job of 'thinking' ahead, to prevent possible errors in the future.
Somebody could, and I have seen it done, place other entities in the url, such as:
In this case the regex I posted would tranlate to Montréal. Not what you want.http://www.test.me/test.pl?me=1&you=1&string=Montréal
Don
WHITEPAGES.COM | INC
Edit by castaway: Closed small tag in signature
In Section
Seekers of Perl Wisdom