Page 2 of 2

Posted: Tue Nov 29, 2005 9:35 am
by foobar
Take a look at your PCRE syntax again.

Posted: Tue Nov 29, 2005 10:19 am
by spacebiscuit
Sorry about the cross posting I did not know where I should be posting in php code or in regex.

What is PCRE?

Rob.

Posted: Tue Nov 29, 2005 10:29 am
by spacebiscuit
\d ......Any single digit (0-9)

/\d{4}/ ......we can specify how many times a character should occur

Therefore I see no reason why this won't work....

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", "18.58");

Posted: Tue Nov 29, 2005 10:48 am
by Jenk

Code: Select all

<?php

$string = "DATA 1: testa DATA 2: testb DATA 3: testc"; 

$values = preg_split("/DATA \d+\: /", $string);

array_shift($values);

print_r($values);

?>
EDIT: That'll teach me to not read the rest of the thread!!!1oneoneone

Posted: Tue Nov 29, 2005 11:19 am
by foobar
robburne wrote:What is PCRE?
Whaddya know... it's in the PHP Manual!

Thanks for taking the time to RTFM! :roll:
robburne wrote:

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", "18.58");
I'm not going to let you off the hook that easily this time. Go through your code step by step. If you can't figure it out, get The Regex Coach and input the pattern. See what it tells you.

Posted: Tue Nov 29, 2005 2:55 pm
by spacebiscuit
Thanks for the feedback, ok so it seems i have a typo in my expression . duh!

So with the change I am starting to get somewhere becuase.....

Code: Select all

$time=preg_split("/\d{2}.\d{2}/", "POD TIME: 18.00 ");
Is giving me...........

"POD TIME: "

So I think this show I understand the regex, just that I am not using the function correctly as I wantthe second half of the expression not the first.

Rob.

Posted: Tue Nov 29, 2005 3:00 pm
by foobar
robburne wrote:Thanks for the feedback, ok so it seems i have a typo in my expression . duh!

So with the change I am starting to get somewhere becuase.....

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", "POD TIME: 18.00 ");
Is giving me...........

"POD TIME: "

So I think this show I understand the regex, just that I am not using the function correctly as I wantthe second half of the expression not the first.

Rob.
Good. The function you'll want to use is preg_match_all(). What you are doing now, is splitting your string along each occurrence of two numbers separated by a dot. Using preg_match* you'll retrieve those numbers instead.

Posted: Tue Nov 29, 2005 3:10 pm
by spacebiscuit
Thanks Foobar, I actually remember doing regular expressions in University about 5 years ago and although I found them interesting I never thought I would be using them in the big wide world!

I'll give the other function a try.

Thanks,

Rob.