Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple regex 4

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
hi,

how should the regex look for numbers like

35TH
12TH
235TH

thanks

-DNG
 
2 or 3 digits followed by 2 letters?

Code:
/^\d{2,3}[a-z]{2}$/i
 
You mean, to find them? That would be /(\d+)(TH)/. Then, $1 would be the number.

_________________
Bob Rashkin
 
If you're looking for ordinal numbers, then you can't just look for 'th'. There's also 'st', 'nd', and 'rd' to consider.

A simplistic version would be:
/(\d+)(st|nd|rd|th)/

although that would also accept 51th, 22rd and 90st
 
[tt]var rx=/\b([0-9]*(1[0-9]th|[02-9](1st|2nd|3rd|[4-9]th))|(1st|2nd|3rd|[04-9]th))\b/i;[/tt]
 
Sorry for the delay in my reply...I really appreciate all your replies...have stars...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top