Re: preg_split() - pattern problem

From: Date: Mon, 11 Nov 2002 18:39:09 +0000
Subject: Re: preg_split() - pattern problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123856@lists.php.net to get a copy of this message
On Tuesday 12 November 2002 02:26, Tobias Talltorp wrote: > How would I write the pattern for this preg_split()? > "/T.*O.*B/", seems to only return the first and last portion of the string > (1: Once upon a time, 2: going for a walk). > > $string = "Once upon a time T:O.B there was a T.O,B duck who was T-O'B > going for a walk"; > > $array = preg_split('/T.*O.*B/', $string, -1, PREG_SPLIT_OFFSET_CAPTURE); It's doing a greedy match, thus your pattern is actually matching {T:O.B there was a T.O,B duck who was T-O'B} 1) Check whether there's a flag in PRCE to do ungreedy matches. or 2) Maybe you really meant your pattern to be /T.O.B/ which matches T{any single char}O{any single char}B -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Save energy: be apathetic. */

« previous php.general (#123856) next »