View Full Version : Regular expression help

05-01-2009, 08:42 AM
I'm cleaning up the remains of a virus

How would I remove


in the following code

<iframe>bad code</iframe><iframe>junk</iframe>

If I use the regex:

<iframe.*bad code.*iframe>

it matches

<iframe>bad code</iframe><iframe>junk</iframe>

not just the

<iframe>junk</iframe> that I wanted.

I hope that makes sense :)

05-01-2009, 10:31 AM
well your code is make sense
you ask to start with <iframe. in the mid you want "bad code". and in the end you want iframe>.
<iframe>bad code</iframe><iframe>junk</iframe>

you need to get more specific on your regex if you want only bad code.
i ended it with "e</iframe>"
match <iframe>bad code</iframe>

or <iframe>j.*k<\/iframe>
match <iframe>junk</iframe>

or <iframe>junk<\/iframe>
match <iframe>junk</iframe>

i had this virus too
on the end of the page before the </body>

05-01-2009, 10:34 AM
thanks but the bad code can be anything

05-01-2009, 10:35 AM
I should be more specific, its the

<iframe>junk</iframe> that I need to match

05-01-2009, 10:36 AM
what are you tring to do?
you want to delete the bad code or junk?

05-01-2009, 10:57 AM
junk and bad code could be anything or there are some sort of a string that can ident the "junk"

05-01-2009, 08:23 PM
try this:


$text = '<iframe>bad code1</iframe><iframe>bad code2</iframe><iframe>bad code3</iframe><iframe>bad code4</iframe><iframe>bad code5</iframe><iframe>bad code6</iframe><iframe>junk</iframe>';

function reg($v){
$v = preg_replace("/\//","\/",$v);
return '/('.$v.')/';

$re1 = array_map("reg",$matches[1]);
$re2 = array_fill(0,count($re1),'$1');

$result = preg_replace($re1,$re2,$text);

print $result;


best regards

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum