Jump to content

PCRE Syntax Help


musclehead

Recommended Posts

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!!

Link to comment
https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381336
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/75377-pcre-syntax-help/#findComment-381342
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.