I have a string with many lines and one of those lines is a temperature reading and the method used to take the temperature like so:
Example line 1
temp: 35.20c / 95.36f - axillary
Example line 2
Obviously the temp is "35.20c / 95.36f", and the method is "axillary". The method part is optional. I'm having problems writing a REGEX pattern that will extract both since the method can be optional.
So if i run the pattern in a preg_match_all() on the following string:
temp: 35.20c / 95.36f - axillary
temp: 35.20c / 95.36f
temp: 35.20c / 95.36f - oral
I would expect to get a print similar to this:
Array
(
[0] => Array
(
[0] => temp: 35.20c / 95.36f - axillary
[1] => temp: 35.20c / 95.36f
[2] => temp: 35.20c / 95.36f - oral
)
[1] => Array
(
[0] => 35.20c / 95.36f
[1] => 35.20c / 95.36f
[2] => 35.20c / 95.36f
)
[2] => Array
(
[0] => axillary
[1] =>
[2] => oral
)
I have tried many different patterns, so I'll just post my original (which makes sense to me):
$ptn = "/temp: *(.+)(?: - )?(.+)?/";
Sorry guys I guess I need to add some more details:
- I have no idea what kind of format the temp will be displayed in (35.20c / 95.36f, 35c, 95.3f, etc)
- I basically just need to take everything after the "temp: " and before the hyphen as my temp and everything after that is going to be my method.