Reputation: 1303
I am attempting to split validated addresses into the base components (Unit #, Street #, Street Name etc). To do this I am working backwards (right to left) through the string:
Now, I am able to write the three regex patterns to do this matching. What I am unsure of is how to use them. This will be used in batch processing of addresses.
My ideas are:
Any advice on how the most efficient use of regular expressions would be most helpful.
EDIT As suggested I used groups to do this instead. In case anyone wants to see what I came up with:
(?<unit>(.*))\s(?<number>([\d-]+[A-Za-z]{0,1}))\s+(?<name>([\sA-Za-z'-]+$))
NB: This is for a very particular format of addresses, specific to what I need.
Upvotes: 0
Views: 82
Reputation: 3991
Regular expressions are capable of matching the entire string; just enclose the parts in parentheses to form capturing groups, e.g.:
^(\w*)\s*([\d-]+[A-Za-z]?)\s*(.+)$
Then examine the Match.Groups
collection for the parts you need.
Upvotes: 2