Allasso has asked for the wisdom of the Perl Monks concerning the following question:
I have this routine that takes all the spaces in between a string of adjacent html tags. Only problem is it also takes the spaces out of the tags themselves. I cannot understand why this is happening.
eg: <span class="c"> becomes <spanclass="c">
$newtoken = ""; while ("$token" ne "$newtoken") { $newtoken = "$token"; $token =~ s@((?:<[^>]*>)*) +((?:<[^>]*>)*)@\1\2@g; }
If I put a "dot" metacharacter as below, it fixes it, but I don't understand why. If I am back-referencing the whole tag, why would anything inside the back-reference be affected?
$newtoken = ""; while ("$token" ne "$newtoken") { $newtoken = "$token"; $token =~ s@((?:<[^>]*>).*) +((?:<[^>]*>).*)@\1\2@g; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: spaces removed in backreference
by graff (Chancellor) on Apr 25, 2010 at 05:10 UTC | |
by Allasso (Monk) on Apr 25, 2010 at 09:49 UTC | |
|
Re: spaces removed in backreference
by ig (Vicar) on Apr 25, 2010 at 03:10 UTC | |
by AnomalousMonk (Archbishop) on Apr 25, 2010 at 04:43 UTC | |
|
Re: spaces removed in backreference
by Anonymous Monk on Apr 25, 2010 at 03:16 UTC | |
|
Re: spaces removed in backreference
by Allasso (Monk) on Apr 25, 2010 at 14:47 UTC | |
|
Re: spaces removed in backreference
by Allasso (Monk) on Apr 25, 2010 at 09:46 UTC |