Re: Regular Expression

From: Date: Wed, 05 May 2004 05:35:37 +0000
Subject: Re: Regular Expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185396@lists.php.net to get a copy of this message
On Wed, May 05, 2004 at 02:26:25PM +0900, Tumurbaatar S. wrote: > > There's an input string like "{str1,str2,...,strN}". I want to capture > all these strings and due to complexity of them I use a preg_match_all() > instead of simple split. A pattern for the matching strings is ready but > I cannot imagine how to specify that strings are separated by commas > and the last one is not followed by comma. For example, I'm afraid that > this pattern "/^{(?:(pattern),)*|(pattern)?}$/" can match and capture > properly constructed input string, but, in addition, this matches if > the string end is ",}". Any ideas? Why not just strip out the braces and explode on commas? That'll be lighter than regexps any day. If the input is guaranteed to be formatted the way you describe, you could do something like: $out = explode(",", substr($in, 1, strlen($in)-2)); -- Paul Chvostek <paul@it.ca> it.canada http://www.it.ca/ Free PHP web hosting! http://www.it.ca/web/

« previous php.general (#185396) next »