ionik Posted June 28, 2008 Share Posted June 28, 2008 Heres my problem I need to match this Link : text Description : text as a array with the link => text and description => text as two separate arrays I am using preg_match like this <?php $string = 'Link : http://link.com Description : Some information Here!!'; preg_match('/Link : (.*?)/is', $string, $matches1); print_r($matches1); preg_match('/Description : (.*?)/is', $string, $matches2); print_r($matches2); ?> why isnt this working ? the output of this is Array ( [0] => Link : [1] => ) Array ( [0] => Description : [1] => ) Quote Link to comment https://forums.phpfreaks.com/topic/112267-regex-wont-match/ Share on other sites More sharing options...
sasa Posted June 29, 2008 Share Posted June 29, 2008 try <?php $string = 'Link : http://link.com Description : Some information Here!!'; preg_match('/link : (?P<Link>[^ ]+) description : (?P<Description>.*)/i',$string, $match); print_r($match); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112267-regex-wont-match/#findComment-577096 Share on other sites More sharing options...
effigy Posted June 30, 2008 Share Posted June 30, 2008 To clarify, the regex is matching. (.*?) is lazy and nothing follows it, thus, it is satisfied at matching nothing. Quote Link to comment https://forums.phpfreaks.com/topic/112267-regex-wont-match/#findComment-578247 Share on other sites More sharing options...
kucing Posted July 1, 2008 Share Posted July 1, 2008 How about this one? $string = 'Link : http://link.com Description : Some information Here!!'; preg_match('/Link : (.*?)\s.*/is', $string, $matches1); print_r($matches1); preg_match('/Description : (.*?)\s.*/is', $string, $matches2); print_r($matches2); Quote Link to comment https://forums.phpfreaks.com/topic/112267-regex-wont-match/#findComment-578834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.