|
Posted by Rik on 11/19/04 11:46
Mark wrote:
> D excellent. then I just need the first letter after each integer,
> and
> the rest should be easy.
> thank you.
preg_match_all("/([0-9]+)[\s]*([a-zA-Z]?)/i",$input,$matches);
Regex workbench explains it like this:
Capture
Any character in "0-9"
+ (one or more times)
End Capture
Any character in "\s"
* (zero or more times)
Capture
Any character in "a-zA-Z"
? (zero or one time)
End Capture
Matching: 3h
0 => 3h
1 => 3
2 => h
Matching: 3 hours
0 => 3 h
1 => 3
2 => h
Matching: 3 hrs
0 => 3 h
1 => 3
2 => h
Matching: 3h5min
0 => 3h
1 => 3
2 => h
0 => 5m
1 => 5
2 => m
Matching: 3hrs5 minutes6s
0 => 3h
1 => 3
2 => h
0 => 5 m
1 => 5
2 => m
0 => 6s
1 => 6
2 => s
But still... typos can be made, what if someone types "5hours 6ninutes"? How
are you going to interpret "n", which is next to both "h" and "m"?
I still think it shouldn't be done this way, but hey, it's your call
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|