Hello all,
I'm unable to figure out how to process the zip codes with regexes.
We have a custom component that takes a find pattern, a replace
pattern, and the input value, and will output the processed result
string. At the moment we're trying to clean up some zip code data
that has the following inconsistencies, for example:
99d999
99999d
V2X 4B4
unknown
tyrone
SDHJSHD
sasas
na
DSJKDJSKDJ
DKSLDKSLKD
D
999999
99999
99520
99207-4771
I would like to clean up the invalid values and return a null string
instead. If part of the value is valid, I'd like to return that and
drop the rest. So for a given zip code value:
If any of the first five characters are not a digit, select the entire
value and replace it with nothing ("")
If the first five characters are digits, and the next character is a
hyphen, get the next four characters. If they are digits, get all 10
characters. If not, get the five digits from the left
If there are first nine characters are digits, bring only those nine
back
Is it possible to handle this level of conditional processing in a
regular expression? They can run individually or however it needs to
be. I've experimented with lookarounds and regex conditionals but am
not able to figure it out.
Any help is greatly appreciated. Thank you in advance for your time.