Jump to content

delete all images in a page


anarchoi

Recommended Posts

@effigy,

 

Our RegEx's appear to do the exact same thing, but using different logic. After reviewing yours it appears more elegant and easier to understand. However, I'm curious, did you see a flaw in my expression or did you just want to post your version?

My expression is more efficient in theory. It's best to use greediness when you can expect a certain format; for instance, it's impossible for an open HTML tag to contain another (e.g., <img <h1>x</h1>>) and, knowing this, we can tell the engine to race forward gobbling non ">"s, rather than checking at every step along the way to make sure a ">" is not ahead.

 

As a general rule, when you can, be as specific as possible. Greedy quantifiers and negated characters classes are typically more efficient and internally optimized compared to lazy quantifiers.

 

My apologies for not being as informative up front.

Thanks for the elaboration. A quick test verified your position. It's not that I don't believe you - I just always test something, if possible, instead of blindly accepting.

 

Running through 10,000 itterations of both methods gave varrying results, but the latter method was approximately 50% faster: 0.1 seconds vs. .05 seconds. Considering that is for 10,000 itterations the difference may not seem relevant. But, for sites with a large amount of traffic every little bit adds up.

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.