musclehead Posted October 30, 2007 Share Posted October 30, 2007 I'm trying to search a string for instances of UNIX time stamps. My problem is the string contains other strings of digits that are NOT Unix time stamps (but being interpreted as such based on my syntax): preg_match_all('/\d{10}/',$string,$match); The above syntax picks up everything w/ 10 digits, so I tried this to avoid leading zeros: preg_match_all('/^[1-9]{10}/',$worklog,$s); But that is also bailing. I'm just trying to search through a string and find ONLY the Unix time stamp integers...and not pickup any other errant 10-digit strings. From what I can tell, all the other occurrences of 10-digit integers in my string begin with a zero - a nice way to distinguish them from the Unix time stamps...but not with the horrible way I write PCRE. Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/ Share on other sites More sharing options...
toplay Posted October 30, 2007 Share Posted October 30, 2007 Try: /[1-9]\d{9}/ Quote Link to comment https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381287 Share on other sites More sharing options...
musclehead Posted October 30, 2007 Author Share Posted October 30, 2007 No dice, toplay. Unfortunately that will leave out any valid UNIX timestamps that have zeros within them - I need to eliminate 10-digit integers within the string that BEGIN with zeros. NOTE: Scratch that...my bad...overlooked the entirety of your recommendation. Working very well - thank you for your help, toplay! Quote Link to comment https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381336 Share on other sites More sharing options...
toplay Posted October 30, 2007 Share Posted October 30, 2007 No dice, toplay. Unfortunately that will leave out any valid UNIX timestamps that have zeros within them - I need to eliminate 10-digit integers within the string that BEGIN with zero. Did you even try it? the [1-9] at the beginning will only match integers not starting with zero. Then the \d will match 0-9 and {9} looks for another 9 digits, so a total of 10 altogether. Quote Link to comment https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381342 Share on other sites More sharing options...
musclehead Posted October 30, 2007 Author Share Posted October 30, 2007 I did...sorry about that. I overlooked syntax in your recommendation and now it's working perfectly. thank you very much for you help! Quote Link to comment https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381344 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.