How can I use regexextract function in Google Docs spreadsheets to get “all” occurrences of a string?

前端 未结 2 1689
遥遥无期
遥遥无期 2021-02-07 23:18

My text string is in cell D2:

Decision, ERC Case No. 2009-094 MC, In the Matter of the Application for Authority to Secure Loan from the National Electrification         


        
2条回答
  •  别那么骄傲
    2021-02-07 23:54

    You can use capture groups, which will cause regexextract() to return an array. You can use this as the cell result, in which case you will get a range of results, or you can feed the array to another function to reformat it to your purpose. For example:

    regexextract( "abracadabra" ; "(bra).*(bra)" )
    

    will return the array:

    {bra,bra}
    

    Another approach would be to use regexreplace(). This has the advantage that the replace is global (like s/pattern/replacement/g), so you do not need to know the number of results in advance. For example:

    regexreplace( "aBRAcadaBRA" ; "[a-z]+" ; "..." )
    

    will return the string:

    ...BRA...BRA
    

提交回复
热议问题