I am looking to find the initial letters of a UK post code before the first number.
UK Post codes start with 1 or 2 letters and are always numbers and then letters.
E.g. ‘WA1 1AB’ or ‘SK2 3LP’ or ‘L1 1AA’ or ‘M2 3NK’
I am looking for a formula to return the initial letters before the first number.
So for the above examples, I would expect ‘WA’, ‘SK’, ‘L’ and ‘M’
Solved! Go to Solution.
:wave: Hey there!
Just a little regex knowledge can go a long way though! It’s definitely worth dipping your toes into
The caret (^) at the start tells the interpreter to only look for matches at the start of the string. The token
\D matches any non-digit character, and the asterisk says to match the previous token zero or more times. In short, it matches all non-digit characters at the start of the string. Once a digit is found, the match stops.
FWIW the extra backslash before
\D is required because the backslash in formula strings is an escape character. To ensure that the backslash before the D is maintained as part of that token, you need two backslashes, essentially escaping the escape character itself.
I recommend playing around on regex101.com if you want to learn more about Regex in a hands-on way. It’s not the only site where you can do this, but it’s my favorite so far. Just make sure that you set the “Flavor” option (upper left) to “Golang,” which is the closest Regex variant to what Airtable uses.