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
  • 24,402

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.

2

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

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,595