3

I am using Privoxy 3.0.10.0 to filter web pages before they're passed on to the browser.

I can't figure out why this simple regex doesn't trigger a rewrite. Maybe someone more experienced will have an idea:

Here's what it looks like when I hit Firefox's CTRL-U to view the HTML source:

<font color=#FF4AFF>JohnDoe</font>

Here's my regex; I've also added the "i" switch to ignore case, to no avail

s|(<font color=.+?>JohnDoe</font>)|<span class=myclass>$1</span>|g

Thanks for any hint.

Jeff Atwood
  • 23,972
  • 30
  • 99
  • 120
  • 1
    Shouldn't this be moved to serverfault? – chakrit Jul 25 '09 at 09:42
  • 1
    Given RichieHindle's answer: are you sure you want to embed **the full** original within `` tags, or did you expect only the `JohnDoe` part to be copied, like `JohnDoe`? Just to make sure that you're not overlooking `JohnDoe` in the result. – Arjan Jul 25 '09 at 10:31

3 Answers3

4

The regex itself works fine, as this Python example shows:

import re
print re.sub(r"(<font color=.+?>JohnDoe</font>)",
             r"<span class=myclass>\1</span>",
             "<font color=#FF4AFF>JohnDoe</font>")
# Prints <span class=myclass><font color=#FF4AFF>JohnDoe</font></span>

(assuming Privoxy uses the same regex syntax, barring the \1 vs. $1 difference, but it looks like it does.)

I guess the problem lies elsewhere - try a regex that can't fail, like replacing a with b, to see whether it's having any effect at all.

RichieHindle
  • 742
  • 4
  • 9
2

Thansk guys. Turns out Privoxy was greedy, and I didn't notice that it was taking much more data than I thought.

OverTheRainbow
  • 5,713
  • 20
  • 66
  • 91
0

Not sure what RE engine you're using, but try changing the $1 to \1 - that's how backreferences are usually referred to in perl, at least.

chris
  • 9,287
  • 20
  • 67
  • 85
  • Sometimes you'll need to use \\1, depending on in what format you're writing the regex. – jtbandes Jul 25 '09 at 16:58
  • 1
    In Apache's URL rewriting, one would use $1. But, if \1 should indeed be used in this case, then I'd expect the output to be `$1` -- which hopefully would have been noted in the question then... – Arjan Jul 25 '09 at 18:10