shlumph Posted December 8, 2009 Share Posted December 8, 2009 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 More sharing options...
cags Posted December 8, 2009 Share Posted December 8, 2009 "#\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 https://forums.phpfreaks.com/topic/184436-finding-employee-number/#findComment-973615 Share on other sites More sharing options...
shlumph Posted December 8, 2009 Author Share Posted December 8, 2009 Thanks broseph. This works and I can make tweaks to it, there's no rush, enjoy pool. Link to comment https://forums.phpfreaks.com/topic/184436-finding-employee-number/#findComment-973745 Share on other sites More sharing options...
salathe Posted December 8, 2009 Share Posted December 8, 2009 I see the pattern slightly differently, something like /\b(?:[0-9A-Z]+-)+[0-9]{2}\b/ (if that makes sense). Link to comment https://forums.phpfreaks.com/topic/184436-finding-employee-number/#findComment-973755 Share on other sites More sharing options...
cags Posted December 9, 2009 Share Posted December 9, 2009 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 https://forums.phpfreaks.com/topic/184436-finding-employee-number/#findComment-974058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.