1. REGEXTEST 函數簡介
Excel 中的 REGEXTEST 函數是一個用於驗證文本是否符合特定模式的工具。它在數據清理、輸入驗證(如電子郵件、電話號碼等)以及從文本數據中提取有價值的見解方面非常有用。通過整合正則表達式,用戶可以有效地識別不匹配或驗證數據格式,從而提高整體數據完整性。

2. REGEXTEST 函數參數
這是使用
REGEXTEST
函數的語法。=REGEXTEST(text, pattern, [case_sensitivity])
text
: 必填 要匹配的文本或包含文本的單元格的引用。 pattern
: 必填 描述要匹配的文本模式的正則表達式("regex")。 case_sensitivity
: 選填 確定匹配是否區分大小寫。默認情況下,匹配是區分大小寫的,即默認為 0。可選值為: 0
: 區分大小寫1
: 不區分大小寫3. 示例場景:驗證 Email 地址
假如我們收集到一些 Email 地址,我們想要知道這些 Email 是否是一個有效的 Email 地址。


4. 開始使用 REGEXTEST 函數
鍵盤輸入:
=REGEXREPLACE(
,然後選擇 A5
作為要處理的文本。
5. Email 的正則表達式
這裏我們設置校驗 Email 的正則表達式為:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

6. Email 的正則表達式解析
這裏是 Email 的正則表達式的解析。
文本:
正则表达式:
[email protected]
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
1
john.doe
[a-zA-Z0-9._%+-]+
2
@
@
3
company
[a-zA-Z0-9.-]+
4
.
\.
5
com
[a-zA-Z]{2,}
1
[a-zA-Z0-9._%+-]+
[a-zA-Z0-9._%+-]
字符集.
, 字符 _
, 字符 %
, 字符 +
, 字符 -
.+
數量2
匹配字符:"@"@
字符3
[a-zA-Z0-9.-]+
[a-zA-Z0-9.-]
字符集.
, 字符 -
.+
數量4
匹配字符:"."\.
字符5
[a-zA-Z]{2,}
[a-zA-Z]
字符集{2,}
數量7. REGEXREPLACE 函數生效
回車保存後,我們可以看到 Email 地址是否符合正則表達式的規則。
如果符合,返回
如果符合,返回
TRUE
;如果不符合,返回 FALSE
。
8. 應用到其他行
把同樣的函數應用到其他行,我們可以快速驗證所有的 Email 地址。

