Search code examples
regexgoogle-sheets

Positive lookahead in Google sheets regex


I have a list of strings as shown in below table. Using regex, I want to extract the string that is before the last comma(,) in each string.

Book name
Blue Lock, 1
Naruto, Vol. 9
Harry Potter (novel), Vol 2

I have found the regex that does this, /^.*(?=,\s[vV]ol)/, but when I use the same in Google sheet, it throws an error that says '"^.*(?=,\s[vV]ol)" is not a valid regular expression'.

What do I need to change to make the regex work on Google sheets?

Thank you!


Solution

  • Google Sheets regex doesn't support lookarounds.

    Try:

    =REGEXEXTRACT(A1,"(.*),")