Re: preg_replace pain!

From: Date: Thu, 18 Jan 2001 14:44:50 +0000
Subject: Re: preg_replace pain!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35352@lists.php.net to get a copy of this message
On Thu, 18 Jan 2001, Christian Reiniger wrote: > On Thursday 18 January 2001 07:40, Nicholas Pappas wrote: > > > I was hoping someone could help me with this regular expression... > > > > $pattern = "/\[b\](.*)\[\/b\]/Ui"; > > $message = preg_replace($pattern, "<B>\\1</B>", $message); > > > > The above works for: > > [b]bold text[/b] > > > > But does not work for: > > [b]bold text > > w/ newline[/b] > > add a "s" modifier to the expression and > > => > > $pattern = "/\[b\](.*)\[\/b\]/Uis"; That, and: $pattern = "|\[b\](.*?)\[/b\]|is" Shorter regex by one character, and you can use it in perl, too. Remember, U is a tacked on feature, but ? has always been there, it's your friend. I used pipes to remove the necessity of escaping the forward slash. Cheers! -- +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Shaun M. Thomas INN Database Programmer | | Phone: (309) 743-0812 Fax : (309) 743-0830 | | Email: sthomas@townnews.com AIM : trifthen | | Web : www.townnews.com | | | | "Most of our lives are about proving something, either to | | "ourselves or to someone else." | | -- Anonymous | +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

« previous php.general (#35352) next »