Re: reg ex help

From: Date: Wed, 09 Nov 2005 02:41:25 +0000
Subject: Re: reg ex help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-225369@lists.php.net to get a copy of this message
On Fri, November 4, 2005 12:09 pm, conditional motion wrote: > New to php so please bear with me. I'm trying to parse through a > field that has some information in it, the information is stored with > other information and is delimited in a certain pattern so I figure > using reg ex I can get the information I want out of the text. > > So here is an example. > > Silver Small Corp;;;;;X^%%%%%\n#####\n > Gold Medium Corp;;;;;RE^%%%%%\n#####\n > Platinum Large Corp;;;;;YRE^%%%%%\n#####\n > > Reall all I need is the information on Silver Small Corp, etc and the > X all the rest is gibberish. Is Reg Ex the best way to do this or > would it be some other way. Try this (untested): <?php $pattern = '/^([^;]*);([^;]*);([^;]*);.*$/m'; //repeat this /^^^^^^\ for each ; bit you need preg_match_all($pattern, $data, $fields); var_dump($fields); ?> The 'm' at the end might need to be an 's', but I think 'm' is right. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#225369) next »