I am fairly new to both php and regular expressions and am having trouble finding my solution. I am not sure if it because I do not know the terms to google or what, but here is my question:
I am trying to use PHP preg_match to find the first set of consecutive numbers in a string. What I mean by consecutive numbers is ANY string where it is uninterrupted numbers.
ex.
'abc123abc' matches: 123 'ghdfk 1 23abc' matches: 1 '2475xyz' matches: 2475 'abc 456 789' matches: 456
I have been looking through regular-expressions.info and google for terms similar to my question topic, but they all seem to return searches for people looking for repeating numbers of specific lengths.
I am trying to parse an address string to the best of my ability, even though it might be horribly entered.
Things I have tried so far that aren't working are in my code:
<?php
#$addr = '12-3 3rd street'; #1st Test
$addr = 'RR 3 Box 8411'; #2nd Test
#$addr = '480jacksonrd'; #3rd Test
#$addr = 'N2626prociousmayselrd'; #4th Test
#list($our['StreetNum'], $our['StreetName']) = explode(" ", $our['Address'], 2);
#preg_match('/.+(?=[^0-9])/s',$addr,$Matches);
#preg_match('/[0-9]*/',$addr,$Matches);
preg_match('/(?<=\[^0-9]).+?(?=[^0-9])/s',$addr,$Matches);
$our['StreetNum'] = $Matches[0];
$our['StreetNum'] = preg_replace("/[^0-9]/", "", $our['StreetNum']);
echo ('First Match?: ' . $Matches[0] . '<br>'); #For Testing
echo ('Second Match?: ' . $Matches[1] . '<br>'); #For Testing
echo ('StrLen of StreetNum: ' . strlen($our['StreetNum']) . '<br>');
echo ('StrPos of StreetNum: ' . strpos($addr,$our['StreetNum']) . '<br>');
$our['StreetName'] = substr($addr, strlen($our['StreetNum'])+strpos($addr,$our['StreetNum']));
echo ('Street Original: ' . $addr . '<br>');
echo ('Street Number: ' . $our['StreetNum'] . '<br>');
echo ('Street Name: ' . $our['StreetName'] . '<br>');
?>
Any help or direction would be greatly appreciated.