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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.