Xaprb

Stay curious!

How to block ads effectively with AdBlock regular expressions

with 4 comments

One of the greatest things about Firefox is the ability to customize the browser with extensions. By far my favorite extension is Adblock. It allows you to specify arbitrary regular expression patterns to block your browser from fetching and displaying content. The regular expression syntax is standard JavaScript syntax, based on Perl 5.

Blocking content is a delicate dance. It’s very easy to block too much, so the patterns need to be fairly specific. The following patterns will match almost any content I don’t want to see on the Internet, and rarely block something I do want to see. Note that these are regular expressions.

  • \.swf
  • \bads\b
  • 2o7
  • a1\.yimg
  • adbrite
  • adclick
  • adfarm
  • adrevolver
  • adserver
  • adtech
  • advert
  • atdmt
  • atwola
  • banner
  • bizrate
  • blogads
  • bluestreak
  • burstnet
  • casalemedia
  • coremetrics
  • doubleclick
  • falkag
  • fastclick
  • feedstermedia
  • googlesyndication
  • hitbox
  • httpads
  • imiclk
  • intellitxt
  • js\.overture
  • kanoodle
  • kontera
  • mediaplex
  • nextag
  • pointroll
  • qksrv
  • rightmedia
  • speedera
  • statcounter
  • tribalfusion
  • webtrends

To use it, join the entire list with | and start and end it with /. The following is everything together as a single regular expression. This is my one and only Adblock filter:

/\bads\b|2o7|a1\.yimg|adbrite|adclick|adfarm|adrevolver|adserver|adtech|advert|atdmt|atwola|banner|bizrate|blogads|bluestreak|burstnet|casalemedia|coremetrics|doubleclick|falkag|fastclick|feedstermedia|googlesyndication|hitbox|httpads|imiclk|intellitxt|js\.overture|kanoodle|kontera|mediaplex|nextag|pointroll|qksrv|rightmedia|speedera|statcounter|tribalfusion|webtrends/

If you’re familiar with regular expressions, you will have realized some of the entries can be combined into one with grouping. Without taking this to extremes, here is the shorter version:

/\bads\b|2o7|a1\.yimg|ad(brite|click|farm|revolver|server|tech|vert)|at(dmt|wola)|banner|bizrate|blogads|bluestreak|burstnet|casalemedia|coremetrics|(double|fast)click|falkag|(feedster|right)media|googlesyndication|hitbox|httpads|imiclk|intellitxt|js\.overture|kanoodle|kontera|mediaplex|nextag|pointroll|qksrv|speedera|statcounter|tribalfusion|webtrends/

I don’t block swf because the flashblock extension blocks Flash more conveniently than AdBlock, in my opinion.

Further Reading:

Written by Xaprb

October 26th, 2005 at 5:05 pm

Posted in Uncategorized

4 Responses to 'How to block ads effectively with AdBlock regular expressions'

Subscribe to comments with RSS

  1. [...] There’s some additional code that to ensure that every image is only grabbed once (to reduce load on both the motorpulse server and the remote server) and to eliminate potential ad images (using this AdBlock regular expression) and plenty of begin/rescue blocks to prevent DNS lookup issues or other weird curl-related errors. However, once the array of images is selected, it’s passed on to the user for selection. Note that the image selection is using image thumbnails resized by the user’s browser (with typically poor sampling) instead of motorpulse.com-served thumbnails. I decided it just wasn’t necessary to impact the server and make the user wait while motorpulse downloads all of the images, resizes them, offers them up for selection, and then deletes all but the selected one. [...]

  2. I prefer Adblock Plus, which is a better-developed fork of Adblock that allows blocking for more types of elements. I offer my own Adblock Plus pattern list on my blog.

    Tim McCormack

    24 Oct 06 at 12:57 am

  3. Thanks, I’ll have to take a look at that sometime. Right now Adblock is still working great for me, but I might not know what I’m missing!

    Xaprb

    30 Oct 06 at 10:47 am

  4. Could anyone on this thread give me some insight into how AdBlock uses the RegExp pattern to target the content on the page.

    I need to write a bit of Javascript that detects ads and then highlights them on the page. Is it just a matter of finding the elements on the page that contain the String patterns?

    Lee Probert

    16 Sep 09 at 10:57 am

Leave a Reply