You are here: Re: Help with regular expression « PHP Programming Language « IT news, forums, messages
Re: Help with regular expression

Posted by Chung Leong on 09/28/61 11:37

Tony Marston wrote:
> I am seeking help with a regular expression that will split a string into
> several parts with ',' (comma) as the separator, but NOT where the separator
> is enclosed in parentheses. For example, take the string "field1,
> CONCAT(field2,' ', field3) as field23, field4". I would like to be able to
> split this into the following:
> [0] field1
> [1] CONCAT(field2,' ', field3) as field23
> [2] field4
>
> Thanks in advance.
>
> --
> Tony Marston
> http://www.tonymarston.net

This works for the text format you described. Doesn't work in
situations where you might have paraphrases inside literal strings. For
that you'd need a solution like that one Pedro suggested.

preg_match_all('/\s*([^,]*\(.+[^\)]\)[^,]*|[^,]+)\s*/', $text, $m);
$list = $m[1];

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация