Simple expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Locked
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Simple expression

Post by spacebiscuit »

Ok,

I have read the tutorial I understand the tutorial yet this will not work...........

here is my string.......

"POD DATE: 18.58 POD TIME 123456"

I want to extract the time part of the string "18.58"

So I am using..........

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", $message);
That is..... any occurence of 2 digits followed by a fullstop followed again by 2 occurences of a digit.

Can it be any simpler than that can it?

My output is giving me.........

Code: Select all

Array ( [0] => POD DATE: 18.58 POD TIME 123456 )
Now if you can tell me how that came about then you're a better programmer than me!

Thanks,

Rob.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Don't crosspost.

viewtopic.php?t=41324
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

you have a typo in your expression

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", $message);
you have a ] instead of a } on the last quantity specifier
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

sweatje wrote:you have a typo in your expression

Code: Select all

$time=preg_split("/\d{2}.\d{2]/", $message);
you have a ] instead of a } on the last quantity specifier
Good job letting people figure stuff out for themselves. Check out the other thread I linked to. :roll:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I've locked this thread since you've asked your question in another one one of your threads that is related to regex. We want to avoid people answering in 2 different area.
Good job letting people figure stuff out for themselves.
Thats not called for :?
Locked