sorry, should have added that i'm not aware of any library to do this, but you could certainly write one! :) and i forgot to use the list, sorry. - isaac On Fri, Jul 10, 2009 at 10:28 AM, Isaac Dover <isaacdover@xxxxxxxxx> wrote: > though this looks suspiciously like a homework assignment, i'll bite. > > those regex patterns wouldn't solve his problem. he wants to pull > repetitions from the string _before_ knowing a pattern. those patterns will > match the entire source string > > without trying, i would think that you may try using a technique that reads > a character, then looks for the next occurrence of that character. if you're > lucky, then that character will be the beginning of the sequence. you'll > just look at the substring from that first occurrence until the next, then > search the string for that substring. > > if unlucky, you'll move to the next string, _append it_ to the previous, > repeat the process, and so on. at some point, you'll have the pattern built > in memory and will be searching the source string using your built "pattern > string". at some point, something will have to match. > > the trick is in recursion. also, i'm assuming your real examples are more > complicated than what you have above. in the two listed, you already know > that a zero indicates that the pattern is beginning, so you just look for, > and note the index of, zeroes. > > i've thumbed through a free book online that deals with text parsing. it's > very technical, but interesting at the same time. maybe you can find it. > > - isaac > > > On Wed, Jul 8, 2009 at 11:32 PM, WenDong Zhang <zwd2005@xxxxxxxxx> wrote: > >> yes >> (\d+?)\1+ works fine >> >> On Thu, Jul 9, 2009 at 6:00 AM, Per Jessen <per@xxxxxxxxxxxx> wrote: >> >> > Rob Gould wrote: >> > >> > > Can anyone tell me if there's a PHP library out there that will help >> > > me determine "pattern sequences" from a string? >> > > >> > > >> > > Example input: >> > > >> > > 032258064516129032258064516129032258064516129032258064516129 >> > > Sequence = 032258064516129 >> > > >> > > >> > > 037037037037037037037037037037037037037037037037037037037037 >> > > Sequence = 037 >> > > >> > > >> > > I know regex can help you find a pattern when you know what the >> > > pattern is already, but this is different. >> > >> > Nah, it's the same thing. >> > >> > A suitable regex might look something like this: >> > >> > /([0-9]+)\1+/ >> > >> > Not tested, probably won't work on the first try. You may need >> > greediness adjustments. >> > >> > >> > /Per >> > >> > >> > -- >> > Per Jessen, Zürich (14.1°C) >> > >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> >> >> -- >> Best Regards! >> Wen Dong >> > >