Google Spreadsheets Regex Case Insensitive (Regexreplace)

前端 未结 4 603
情歌与酒
情歌与酒 2020-12-29 23:41

I\'m trying to create a case insensitive regex query in Google Spreadsheets with the regexreplace function. Is that possible? I\'ve tried the \\i flag and got a #REF error s

相关标签:
4条回答
  • 2020-12-30 00:12

    AFAIK, the only way to enable case-insensitive matching is JavaScript API in google docs.

    Apparently, RE2 syntax does support the inline (?i) case-insensitive modifier:

    =REGEXREPLACE("Test", "(?i)t", "")
    

    An alternative that will work is using a Character class, adding both cases of the letter T..

    =REGEXREPLACE("Test", "[Tt]", "")
    
    0 讨论(0)
  • 2020-12-30 00:21

    There is NO flag for case sensitivity If you have a longer string and you want to make it case insensitive you cold try use a lowercase regular expression and make your test lowercase usign the function lower: =REGEXREPLACE(LOWER(string), regex_in_lowercase, replacement) in your specific case: =REGEXREPLACE(LOWER("test"), "t", "") The problem is that a capture expression with be in lowercase! source: https://productforums.google.com/forum/#!topic/docs/7kNb9LGeIfM

    0 讨论(0)
  • 2020-12-30 00:22

    As Alexander Ivanov wrote,

    Yes, I'm understand that this topic has resolved. But I found something fancy!

    =REGEXREPLACE("Test","(?i)t","") It returns what you want

    es

    P.S.: Please, if somebody knows why it works then comment.

    Google uses their own re2 regular expressions engine. Using (?i) is allowing you to set the flags for case insensitive search https://re2.googlecode.com/hg/doc/syntax.html

    0 讨论(0)
  • 2020-12-30 00:28

    I found this:

    =REGEXREPLACE("Test","(?i)t","")
    

    It returns what you want

    es
    

    google/re2

    0 讨论(0)
提交回复
热议问题