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
https://forums.phpfreaks.com/topic/184436-finding-employee-number/
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).

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. :)

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.