Jump to content

Finding Employee Number


shlumph

Recommended Posts

Hi,

 

I've been trying to use a regular expression to find employee numbers in a string of text.

Example:

This is a string of text. The employee number is: 123W45-01 The time is: 01:32:55

 

 

All employee numbers will end in and "-" followed by two digits. However, there can be multiple "-"'s throughout the number:

Example:

This is another string of text. The employee number is: 132-123-23W45-01 The time is: 21:51:32

 

Any ideas for a regular expression to find the bolded employee ID's?

Link to comment
Share on other sites

"#\b[1-9a-z-]+?-[0-9]{2}\b#i"

 

There are likely more restraints like only certain characters are used, only certain lengths, but based on what you've specified so far, this is the best I can do (though I'm in a rush as I'm running late for pool).

Link to comment
Share on other sites

I see the pattern slightly differently, something like /\b(?:[0-9A-Z]+-)+[0-9]{2}\b/ (if that makes sense).

Makes sense, afterall I doubt double dashes (--) are used.

 

Thanks broseph. This works and I can make tweaks to it, there's no rush, enjoy pool.

I think I enjoyed it a little too much, little hungover. Though that more likely to be the birthday pissup I attended afterwards. :)

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.