...

View Full Version : Regex Pattern Question



JustinMs66
08-04-2007, 06:05 AM
i have been wanting to figure this out for a while now,

say you have:


$text = "<b>test</b><b>test</b>";
$text = preg_replace("/\<b\>(.*)\<\/b\>/","$1",$text);

the "$text" variable is going to hold:

test</b><b>test

but what i WANT it to hold, is this:

testtest


one thing i have done in the past is this:

"/\<b\>([a-zA-Z0-9]+)\<\/b\>/"

but i dont want to have to specify all and every character that can be pressed on a keyboard.

Can anyone help me, please?

kbluhm
08-04-2007, 03:04 PM
Add the modifiers U, s, and i.

'U' makes the pattern ungreedy (and will fix your initial problem)
's' enables multi-line matching (new lines between <b> and </b>)
'i' makes it case insensitive (match both <b></b> and <B></B>)


$text = preg_replace("/\<b\>(.*)\<\/b\>/Usi","$1",$text);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum