On 27 November 2010 13:57, Asmann, Roland <Roland.Asmann@xxxxxxxxx> wrote: > Hi all, > > I am playing around with PHP and BBCodes and have found some regex's > that should transform my BBCode into correct HTML when rendering. > However, I have found that if the BBCode is not correct (eg missing > closing tag), the regex completely eats my input and my page is empty! > > The regex I'm using is: > /\[i\]((\s|.)+?)\[\/i\]/ > > And with an input like: > This is [i]italic. > > I get nothing back. > > What I would like is that when no closing tag is found, the opening tag > should just be shown as-is. Anybody have any idea how I can do this? > > Thanks! > > -- > Roland Asmann > Senior Software Engineer > > adesso Austria GmbH > Floridotower 26. Stock       ÂT +43 1 2198790-27 > Floridsdorfer Hauptstr. 1      F +43 1 2198790-927 > A-1210 Wien             M +43 664 88657566 >                  ÂE roland.asmann@xxxxxxxxx >                  ÂW www.adesso.at > > ------------------------------------------------------------- >       >>> business. people. technology. <<< > ------------------------------------------------------------- > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I think this is a common issue with regex. Trying to use Regex as a parser is no good. At best, regex can be used as a tokenizer. It has limited ability to handle the nesting. The input you gave has no closing [/i], so the regex can't match the string, so nothing is returned. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php