Newbie: to find student ID#s

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
ptyrider
Forum Newbie
Posts: 3
Joined: Tue Mar 04, 2008 10:13 am

Newbie: to find student ID#s

Post by ptyrider »

I need a regex to match 7-digit student ID numbers, presently from 4111509 to 5035465. The first number will always be 4 or 5. Sometimes the ID may have a hyphen after the third digit, like 503-5465. The numbers may not be surrounded spaces but may be more or less embedded in other strings, like "ID#5035465,short report." Thanks for any help. This is a one-off need and I hope you'll spare me the several hours needed to learn regex myself.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Newbie: to find student ID#s

Post by John Cartwright »

I don't take into account everything, but heres a start

Code: Select all

!#*([4-5][\d-]{3,}+)!
ptyrider
Forum Newbie
Posts: 3
Joined: Tue Mar 04, 2008 10:13 am

Re: Newbie: to find student ID#s

Post by ptyrider »

Thanks. Unfortunately, that does not seem to work for me. This one that I did earlier does work except that it can't match numbers starting with 5 (but [4-5] rather than 4 at the beginning doesn't work; I don't really know what I'm doing!):

4[0-9]\d-\d{4}|4\d{6}

will match 4810638 or 481-0638, but not 5810638 or 581-0638
ptyrider
Forum Newbie
Posts: 3
Joined: Tue Mar 04, 2008 10:13 am

Re: Newbie: to find student ID#s

Post by ptyrider »

Ha! I tried again and this seems to work: [4-5][\d]\d-\d{4}|[4-5]\d{6}. Well this thread inspired more thought and eventual success. Thanks again.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Newbie: to find student ID#s

Post by John Cartwright »

ptyrider wrote:Well this thread inspired more thought and eventual success.
That is our goal here :) Happy to hear you got it to work!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Newbie: to find student ID#s

Post by Chris Corbyn »

Code: Select all

/[45]\d{2}-?\d{4}/
Post Reply