Google Spreadsheets Regex Case Insensitive (Regexreplace)

孤街浪徒 提交于 2019-11-29 06:02:52

问题


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 saying the expression was invalid: =regexreplace("Test","t\i","") gives an error when I would hope to get "es" as the final result.

Is it possible? Is there a flag for case sensitivity in Google Spreadsheets?

Thanks in advance!


回答1:


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]", "")



回答2:


I found this:

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

It returns what you want

es

google/re2




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/24644243/google-spreadsheets-regex-case-insensitive-regexreplace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!