ageattack Posted August 25, 2014 Share Posted August 25, 2014 This is my preg_match code: preg_match("/(\d+)|(T)|(A)/", $link, $matches, PREG_OFFSET_CAPTURE, ($off-30) It works and matches the number I want, except it only returns the first character in the $matches array. For instance, if the number it finds is 10, it only returns 1. Now I understand that is what preg_match does, but how would I make that regex ungreedy? I tried adding a *, but it just made an error, and preg match all would keep searching for strings after the first one. All I want is for the first number, regardless of the length of it, to be returned in full. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/290647-how-to-make-preg_match-match-entire-number/ Share on other sites More sharing options...
Solution requinix Posted August 25, 2014 Solution Share Posted August 25, 2014 It is matching 10. To get that value you do $matches[1] with no more array offsets after it. Because if you do $matches[1][0] then you'll get the first character of it. Quote Link to comment https://forums.phpfreaks.com/topic/290647-how-to-make-preg_match-match-entire-number/#findComment-1488924 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.