Re: Regular Expression Problem and PHP 4 (urgent) --- continued

From: Date: Thu, 30 Aug 2001 12:56:26 +0000
Subject: Re: Regular Expression Problem and PHP 4 (urgent) --- continued
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-65270@lists.php.net to get a copy of this message
Andrey, Thanks for the time that you put into this! After some tweaking (for my scripts) I got this working nicely, and learned a thing or two about PREG also. Ross Nielsen chunga668@yahoo.com "Andrey Hristov" <andy@icygen.com> wrote in message news:02d801c12f2e$c1a60a90$0b01a8c0@ANDreY... > Some time spent to try but now i think it works: > > <?php > echo "<pre>"; > $a='datadatadatadata[link1]datadatadata{link2}data[link3]'; > // $a='datadata{link1}data[link2]datadatadata{link3}data[link4]'; > $pattern='/((\[)|\{)(.+?)(?(2)\]|\})/'; > echo $a."\n"; > echo $pattern."\n"; > preg_match_all($pattern,$a,$matches,PREG_MATCH_ORDER); > var_dump($matches); > ?> > > Produces : > <pre>datadatadatadata[link1]datadatadata{link2}data[link3] > /(\[)|\{(.+?)(?(1)\]|\})/ > array(3) { > [0]=> > array(3) { > [0]=> > string(1) "[" > [1]=> > string(7) "{link2}" > [2]=> > string(1) "[" > } > [1]=> > array(3) { > [0]=> > string(1) "[" > [1]=> > string(0) "" > [2]=> > string(1) "[" > } > [2]=> > array(1) { > [0]=> > string(5) "link2" > } > } > > Also works with the commented string. > Explanation : Looking for more than one using preg_match_all. Matching for [ or {, [ is in () because at the end we test if we found > [ so we look for ] otherwise { is found so we look for matching }. (?(1) true|false) is 1 as a backreference is set so we found [. > > Hope this will help you. > > Andrey Hristov > IcyGEN Corporation > http://www.icygen.com > 99% > > > ----- Original Message ----- > From: "Ross Nielsen" <chunga668@yahoo.com> > To: <php-general@lists.php.net> > Sent: Monday, August 27, 2001 9:42 PM > Subject: [PHP] Regular Expression Problem and PHP 4 (urgent) --- continued > > > > Well my first solution didn't really work the way I needed it too so here > > goes again... > > > > Data returned from server process looks like following... > > > > Header > > datadatadatadata[link]datadatadata{link}data[link] > > datadata{link}data[link]datadatadata{link}data[link] > > datadatadatadata[link]datadatadata{link}data[link] > > Closer > > > > I need to grep the values between [] and {} to turn them into a links. > > (BTW I need to retain the values for use in JS) > > Any suggestions? > > > > Thanks, > > Ross > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > >

« previous php.general (#65270) next »