Re: Regexp (ereg) help

From: Date: Fri, 25 Jul 2003 05:25:06 +0000
Subject: Re: Regexp (ereg) help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-156791@lists.php.net to get a copy of this message
* Thus wrote Reuben D. Budiardja (reubendb@innovativethought.com): > > Hi all, > If I have the following string: > $str = "This is a %ANS[1] test, and %ANS[2] test, and %ANS[10], test" > > and want to use > ereg($pattern, $str, $regs); > > what is the $pattern should be so that in $regs I have > > $regs[1] == "%ANS[1]"; > $regs[2] == "%ANS[2]"; > $regs[3] == "%ANS[10]"; > ... Didn't I just reply to this :) > > In fact, the $pattern should general enough that $regs will be filled with > anything that has the pattern > %ANS[X] > > where X could be any number in any digits (eg. 1,2,10,100,23, etc). Oh, now your making it more complicated.. preg_match_all('/(%ANS\[[0-9]+\])/', $str, $matches); And is tested: http://zirzow.dyndns.org/php/preg_match_all/test.php btw, I am now a ereg* => preg* convert! Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#156791) next »