Reputation:
I am trying get the Regex right for the following scenario but have some trouble. Below is the scenario.
My string looks like this: 141st ST or 141ST ST
I want to get only the 141st
part
Upvotes: 1
Views: 2591
Reputation: 1140
This should work.
[0-9]{3}[A-Za-z]{2}
3 numbers with
[0-9]{3}
1 to 3 digits with
[0-9]{1,3}
and 2 letters with
[A-Za-z]{2}
Upvotes: 3
Reputation: 3446
If you want to be cool you could do it this way to validate the street number too:
\d{0,2}(?:1st|2nd|3rd|[04-9]th)(?= st)
and just use the case insensitive flag
Upvotes: 1