Reputation: 85
I'm trying to write a regular expression for a street address. Example: 124 Street
I'm not really sure how to go about this. So far I have something that looks like this
^[0-9][a-zA-Z]$
.
However this is not working. Any help would be greatly appreciated.
Thanks!
Upvotes: 1
Views: 7442
Reputation: 59997
Perhaps this is a better one
`'^((Flat [1-9][0-9]*, )?([1-9][0-9]* ))?([A-Z][a-z]* )*([A-Z][a-z]*)$'`
Upvotes: 3
Reputation: 27287
^[0-9][a-zA-Z]$
will match a single digit followed by a single letter.
If you want to match any non-empty string consisting of only letters, digits, spaces and periods, use
^[0-9a-zA-Z. ]+$
If you want to match (a string of digits and a space) optional, followed by a string of letters and spaces, that would be
^([0-9]+ )?[a-zA-Z ]+$
Upvotes: 5