D
Dan
OK, I have a perl script that reads in html files and makes some link
replacements. Everything works OK except it changes something it
shouldn't. Here is my line of code:
@getstaf2[0] =~ s!href=\"([^(/)]+)[\.]+([^@?]+)\"!href=\"_miscfiles\/$1\.$2\"!ig;
This code replaces a file of the form <a href="whatever.xxx"> to <a
href="_miscfiles/whatever.xxx">.
Now that works fine, but it seems to change things it shouldn't be,
namely instances of <a href="mailto:[email protected]"> to <a
href="_miscfiles/[email protected]">.
Interestingly, if I have two or more mailto references on a page, it
will nicely not touch the first, but will change the second. More
interestingly, if I take out the global parameter 'g' from the end of
the regex, things for fine for the emails (it doesn't touch them), but
then the actual whatever.xxx replacements don't get done.
So I don't understand why it would (a) leave one alone but not the
other since the 'g' should make it do the same for all instances, or
(b) touch the email references at all. The [^?@] atom should make sure
it skips over any email address that happen to be of the form
(e-mail address removed).
Any help is greatly appreciated!! I've been trying to get this solved
for days!
Thanks,
Dan
replacements. Everything works OK except it changes something it
shouldn't. Here is my line of code:
@getstaf2[0] =~ s!href=\"([^(/)]+)[\.]+([^@?]+)\"!href=\"_miscfiles\/$1\.$2\"!ig;
This code replaces a file of the form <a href="whatever.xxx"> to <a
href="_miscfiles/whatever.xxx">.
Now that works fine, but it seems to change things it shouldn't be,
namely instances of <a href="mailto:[email protected]"> to <a
href="_miscfiles/[email protected]">.
Interestingly, if I have two or more mailto references on a page, it
will nicely not touch the first, but will change the second. More
interestingly, if I take out the global parameter 'g' from the end of
the regex, things for fine for the emails (it doesn't touch them), but
then the actual whatever.xxx replacements don't get done.
So I don't understand why it would (a) leave one alone but not the
other since the 'g' should make it do the same for all instances, or
(b) touch the email references at all. The [^?@] atom should make sure
it skips over any email address that happen to be of the form
(e-mail address removed).
Any help is greatly appreciated!! I've been trying to get this solved
for days!
Thanks,
Dan