![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
Re: How do I write a regex for 'does not contain' a string.by arturo (Vicar) |
on Aug 09, 2002 at 15:14 UTC ( #188933=note: print w/replies, xml ) | Need Help?? |
You're relying on a couple of things here, which may be OK and which may not be. If they are, disregard the code, which was written on the fly (but works with the sample input!). First, consider a line such as: <img src="blern.gif" /><span style="display:block" >foo!</span> That's going to pass your test. There's also that pesky problem that the tag need not all be on the same line:
Pile on top of that the problem that it may already have a style element that doesn't contain the "display:block" and you're looking at trouble. So you could sanitize your input to make sure none of these is the case, but then you might as well make the whole thing more CSS-friendly (image spacers indeed! =). Actually, better than adding the inline style would be creating a class in your stylesheet that specifies display:block. But I'm getting ahead of myself, and probably of where you want to be. A more robust solution than any involving a hand-rolled regex would be to write a filter, presumably using HTML::Parser or a subclass thereof, that does the job, along the following lines:
I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche
In Section
Seekers of Perl Wisdom
|
|