Search code examples
regexsortinggoogle-sheetsfilterre2

RegExtract a value from a comma-separated string


I have a Google Sheet located here: https://docs.google.com/spreadsheets/d/1s7tzyz9A9caaJGbiWPm1CDNBxmnv0Xrh3lb5yj9CDOk/

The first tab simply collects information from a Google Form. Enter your name (all names have been changed to random generator names in example spreadsheet), pick the dates you can attend a concert, and select the instrument you play. Hit submit. Responses are dumped into "Google Form Link" tab.

Then, I want to use the Master List tab to generate a list of people that can attend on each date, which is then broken down by the instrument they play. In the master sheet, the current formula I am using to generate each section is:

=IFERROR(SORT(FILTER('Google Form Link'!$B$2:$B,'Google Form Link'!$D$2:$D = A15,'Google Form Link'!$C$2:$C = REGEXEXTRACT('Google Form Link'!$C$2:$C,".*" & CellThatProvidesTheDate & ".*")),1,TRUE),"")

It is working well for every section EXCEPT that of Wednesday, July 3 because my regex is failing to handle the case between July 3 and July 31. When it compiles the list for July 3, it takes everyone that is available for July 3 and ALSO includes the people that can attend July 31, if they are already not on the list.

The formula I am currently using for the July 3 section is:

=IFERROR(SORT(FILTER('Google Form Link'!$B$2:$B,'Google Form Link'!$D$2:$D = A15,'Google Form Link'!$C$2:$C = REGEXEXTRACT('Google Form Link'!$C$2:$C,".*" & $A14 & ".*")),1,TRUE),"")

I have tried to change the formula to the following one below where I use \b to assert the position after the "3", but this formula does not provide any matches and instead triggers the IFERROR() condition that results in blank cells for all instruments on this date.

=IFERROR(SORT(FILTER('Google Form Link'!$B$2:$B,'Google Form Link'!$D$2:$D = A15,'Google Form Link'!$C$2:$C = REGEXEXTRACT('Google Form Link'!$C$2:$C,"[a-zA-Z]* Wednesday, July 3\b")),1,TRUE),"")

Can anyone steer me in the right direction please? I'm not sure why regex such as [a-zA-Z]* Wednesday, July 3\b is working for me on https://regex101.com/ but not in the Google Sheets formula.

Thank you kindly in advance!


Solution

  • You may replace the whole date matching condition:

    'Google Form Link'!$C$2:$C = REGEXEXTRACT('Google Form Link'!$C$2:$C,"[a-zA-Z]* Wednesday, July 3\b")
    

    with

    regexmatch('Google Form Link'!$C$2:$C,"\b"&$A14&"\b")
    

    Final formula (for Cell_A16)

    =ifna(sort(filter('Google Form Link'!$B$2:$B,'Google Form Link'!$D$2:$D = A15,regexmatch('Google Form Link'!$C$2:$C,"\b"&$A14&"\b")),1,TRUE))
    

    enter image description here