regexgoogle-sheetsgoogle-sheets-formula

Google Sheets Regex for the inconsistent pattern


Attached are the Inputs and Expected Outputs based on which I wanted a common regex pattern which can be used in Google Sheets: Input & expected output

Example: In case of following string in a cell: "30m DEVO-67, DEVO-68 1h DEVO-69, DEVO-70 2h DEVO-75"

Following should be the output: DEVO-67, DEVO-68, DEVO-69, DEVO-70, DEVO-75

Basically wanted to extract all the DEVO followed by Dash and a number from any given string.

I tried following but it is not working:

=REGEXREPLACE(B1,"[0-9]+\S+\s+DEVO-(\d+).*","DEVO - $1")

Solution

  • =REGEXREPLACE(A2,"(?is).*?(DEVO-\d+)","$1, ")
    

    The idea is to select batches of

    "Any unwanted string""DEVO-number"
    

    and replace with

    "DEVO-number",
    

    with case insensitive matching and single line mode: (?is)