Mar 02, 2021 05:19 AM
Being no formula expert, I am assuming that the new REGEX_EXTRACT formula function would be a good way to achieve the following.
I want to extract three digits from a name field. These three digits are always in the same place after an underscore.
Name Field: DAM301_010 POWERHOUSE
Extraction Formula Field: 010
Name Field: DAM204_115 DROP THE BALL
Extraction Formula Field: 115
I apologize if this seems extremely simple and obvious to the pros, but for a formula layman, it’s anything but. :winking_face:
Thank you so much in advance.
Mar 02, 2021 12:03 PM
In Airtable, regular expressions cannot do “look behind” matches, so you need to extract the underscore character along with the digits. Then you can remove the _
character. You can also use REGEX_MATCH
to test if the pattern is found to avoid #ERROR!
when there is not match.
Note: this formula will extract all the digits immediately following the underscore, not just the first three.
IF(
REGEX_MATCH({Name Field}, "_\\d+"),
REPLACE(
REGEX_EXTRACT({Name Field}, "_\\d+"),
1, 1, ""
)
)
Mar 02, 2021 12:21 PM
Thank you so much, @kuovonne
Would this formula do the same thing?
REGEX_EXTRACT({Name Field}, “\d+\b”)
Mar 02, 2021 01:10 PM
Probably. You can easily test it for yourself. I don’t remember if the underscore counts as a word boundary or not for a regular expression.
There are many ways to do things with code. Use what works for you.
Mar 04, 2021 07:27 AM
I realize that. Thank you again for your help, @kuovonne