View Full Version : Regex Pattern Question

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:


but what i WANT it to hold, is this:


one thing i have done in the past is this:


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

Can anyone help me, please?

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);