regexgoogle-sheetsre2

Regex: match up to character OR word with Google Sheets REGEXTRACT


I'm trying to extract a street address in Google Sheets. In my data, the address is followed by either a comma(",") or the word "between" Having trouble writing a REGEXTRACT function that matches up to the comma OR the word

This is as close as I've gotten: ^(.*?)\s,|^(.*?)\sbetween

Which works fine for addresses preceding commas, but not preceding 'between'

Is there a way to write this so it essentially says 'match up to the first instance of X OR the first instance of Y"?

Regex Demo

Thank you


Solution

  • You may use this regex pattern:

    ^(.*)?\s*(?:,|between)
    

    This matches all content