I’m working with a Google Sheets document that gets updated automatically through Zapier. One column contains transaction descriptions from Stripe that include reference codes I need to extract for lookup purposes.
I need help with the right REGEX formula to remove text from both the beginning and end of a string. Here’s what I’m dealing with:
Subscription Payment-88392517-08252023143025
What I want to extract is just the middle part between the dashes:
88392517
The first part before the dash stays mostly the same, but the middle section (which I need) varies in both content and length. The timestamp at the end also changes each time.
What’s the best approach to pull out just that middle portion?
REGEXEXTRACT works great here. Use =REGEXEXTRACT(A1,"-([^-]+)-") to grab what’s between the first and second dash. The pattern finds a dash, captures everything that isn’t a dash, then stops at the next one. I’ve used this for parsing payment data for two years - handles variable length codes perfectly. It’s more flexible than SPLIT if your data changes, like when entries have extra dashes or weird formatting. Works consistently even with mixed character types in the codes.
You can also use MID and FIND together. Try =MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1) - finds the first dash, extracts from there, stops at the second dash. Looks messy but it’s reliable when you need pure text functions without regex. Works in older sheet versions too.
I’ve done similar extractions and SPLIT works way better than REGEX here. Since you’ve got consistent dashes, just use =INDEX(SPLIT(A1,"-"),2) where A1 is your cell. It splits at each dash and grabs the second piece - exactly what you want. It’s cleaner than REGEX and runs faster on big datasets. I use this for invoice parsing all the time and it handles different length middle sections no problem. Just make sure you’ve always got dashes separating your data.