REGEX

REGEX 函數會在其他文字和條件函數中啟用規則表示式的使用。可搭配除了條件(IF、COUNTIF、⋯)或符合(SUBSTITUTE、TEXTBEFORE、⋯)字串以外的所有函數使用。不作為條件或符合文字使用時,REGEX 會傳回基本的規則表示式作為字串值。

REGEX(規則表示式字串, 區分大小寫)

規則表示式字串: 表示規則表示式的字串值

區分大小寫: 判定規則表示式是否應視為區分大小寫的程式值(可留空)。

區分大小寫(TRUE 或省略)常規表示式應區分大小寫。

忽略大小寫(FALSE)常規表示式不應區分大小寫。

附註

  • 規則表示式字串必須遵守 ICU 標準。

  • 如同可以與規則字串值串連,不同 REGEX 表示式也可以彼此串連。 但是若 REGEX 與規則字串串連,則結果會是規則字串而不再是 REGEX。

範例

=COUNTMATCHES("To count all words, use regex.", REGEX("\w+")) 會傳回 6。

=TEXTBEFORE("Get all the text before the first numbers 12345 - and nothing after.", REGEX("[0-9]+")) 會傳回「Get all the text before the first numbers」。

讓 A1:A10 範圍中的每個輸入格包含一個單字,其中 5 個輸入格包含字母 a。

=COUNTIF(A1:A10, REGEX("a+",FALSE)) 會傳回 5。

=SUBSTITUTE("example@example.com: Marina Email", REGEX("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}") & REGEX(": *"), "") 會傳回「Marina Email」。

=SUBSTITUTE("marina@example.com", REGEX("([A-Z0-9a-z._%+-]+)@([A-Za-z0-9.-]+)(\.[A-Za-z]{2,4})"), "$2@$1$3") 會傳回「example.com@marina.com」。

=COUNTMATCHES("Item1, item2, item3", REGEX("item[0-9]")) 會傳回 2。

=COUNTMATCHES("Item1, item2, item3", REGEX("item[0-9]", FALSE)) 會傳回 3。

讓 A1 等於 "Client email: client@example.com"。

=IF(COUNTMATCHES(A1, REGEX("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}")), "We have an email", "No email") 會傳回「We have an email」。

Morty Proxy This is a proxified and sanitized view of the page, visit original site.
有幫助?
字元限制: 250
最大字元限制為 250。
感謝您的寶貴意見。
Morty Proxy This is a proxified and sanitized view of the page, visit original site.