Re: Regex Help
| From: | Ben Ramsey | Date: | Mon, 26 Jan 2004 18:26:10 +0000 |
| Subject: | Re: Regex Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-175796@lists.php.net to get a copy of this message | ||
Check the PHP manual for preg_match() (http://us3.php.net/manual/en/function.preg-match.php).
I did play around with it a little bit, and I think I've got a starting point for you to work with. Try out this code and then play around with it to get the results you need. $matches[2][0] will hold the full line for Mayberry Mob. You could then just use the substr() function to pull the data from that line.
The code is, as follows:
$subject = "
=====================================================
NF [1/21/04] E Race 11 Grade B [5-16] Going F
U Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm Inside
Dream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc Mdtk
Pounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show Inside
Oneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly Inside
Krazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk
Mayberry Mob 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent Ins
Jw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor Mdtrk
Rooftop Comet 56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk======================================================== "; $pattern = "/\[(\d+\/\d+\/\d+|\d+\-\d+)\]|(Mayberry Mob.*)/"; if (preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER)) { print_r($matches); } else { echo "no match."; } Hope that helps! Karthikeyan wrote:
Sorry last time I forgot to put subject on my mail. So here I am putting appropriate subject and sending it. Hi All, Just wondering if somebody can help me with this small regex search. The information I wanted to capture is the one in the Square Bracket. i.e Date : 1/21/04, Race Type: 5-16, Dog Position: 6(Mayberry Mob) ===================================================== NF [1/21/04] E Race 11 Grade B [5-16] Going FU Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm InsideDream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc MdtkPounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show InsideOneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly InsideKrazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk[Mayberry Mob] 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent InsJw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor MdtrkRooftop Comet 56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk======================================================== Looking forward to hear some response. Have a great day. Karthikeyan B