函數會 REGEXMATCH 傳回布林值,指出所提供的字串是否符合指定的正則運算式。 正則表達式是一種簡潔且靈活的符號,用於尋找文字模式。
提供正規表示式功能的 Azure Cosmos DB for NoSQL 系統函式。
語法
REGEXMATCH(<string_expr_1>, <string_expr_2>[, <string_expr_3>])
Arguments
| Description | |
|---|---|
string_expr_1 |
要搜尋的字串運算式。 |
string_expr_2 |
字串運算式,其規則運算式定義為在搜尋時 string_expr_1使用。 |
string_expr_3 |
選用字串運算式,其中包含要與正規表示式 (string_expr_2) 搭配使用的所選修飾元。 如果未提供,預設值是執行沒有修飾元的正則運算式比對。 |
傳回類型
傳回布林運算式。
範例
本節包含如何使用此查詢語言建構的範例。
正規表示式與修飾符相符
在此範例中,該 REGEXMATCH 函數用於匹配各種模式和修飾符。
SELECT VALUE {
noModifiers: REGEXMATCH("abcd", "ABC"),
caseInsensitive: REGEXMATCH("abcd", "ABC", "i"),
wildcardCharacter: REGEXMATCH("abcd", "ab.", ""),
ignoreWhiteSpace: REGEXMATCH("abcd", "ab c", "x"),
caseInsensitiveAndIgnoreWhiteSpace: REGEXMATCH("abcd", "aB c", "ix"),
containNumberBetweenZeroAndNine: REGEXMATCH("03a", "[0-9]"),
containPrefix: REGEXMATCH("salt3824908", "salt{1}"),
containsFiveLetterWordStartingWithS: REGEXMATCH("shame", "s....", "i")
}
[
{
"noModifiers": false,
"caseInsensitive": true,
"wildcardCharacter": true,
"ignoreWhiteSpace": true,
"caseInsensitiveAndIgnoreWhiteSpace": true,
"containNumberBetweenZeroAndNine": true,
"containPrefix": true,
"containsFiveLetterWordStartingWithS": true
}
]
備註
- 此功能受益於範圍索引的使用。 如需詳細資訊,請參閱 範圍索引。