Jerred121 Posted March 1, 2011 Share Posted March 1, 2011 So just when I think i'm getting the hang of REGEX, I realize that I suck still and I can't get this simple extraction to work... I want to extract the temp and the method separately: 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'm even embarrassed to post my sorry pattern, but I'm sure you guys can figure it out. As always, thank you! Link to comment https://forums.phpfreaks.com/topic/229192-embarrassed-to-ask-this-regex-question-but/ Share on other sites More sharing options...
Jerred121 Posted March 1, 2011 Author Share Posted March 1, 2011 Sorry, looks like I forgot to include a sample of the data: temp: 35.20c / 95.36f - axillary temp: 35.20c / 95.36f temp: 35.20c / 95.36f - oral As you can see the " - method" is optional. Link to comment https://forums.phpfreaks.com/topic/229192-embarrassed-to-ask-this-regex-question-but/#findComment-1181051 Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 Might be an easier way, but here is one: preg_match_all('#^temp: ([^ ]*) / ([^- ]*)(?: - (.*))?$#m', $s, $m); Link to comment https://forums.phpfreaks.com/topic/229192-embarrassed-to-ask-this-regex-question-but/#findComment-1181988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.