indexof_regex()
適用於:✅Microsoft網狀架構✅Azure 數據✅總管 Azure 監視器✅Microsoft Sentinel
傳回輸入字串內指定查閱 正則表示式 第一次出現之以零起始的索引。
請參閱 indexof()
。
語法
indexof_regex(
字串,
比對[,
開始[,
長度[,
出現次數]]])
深入瞭解 語法慣例。
參數
姓名 | 類型 | 必要 | 描述 |
---|---|---|---|
string | string |
✔️ | 要搜尋的來源字串。 |
match | string |
✔️ | 正 則表達式 查閱字串。 |
start | int |
搜尋開始位置。 負值會透過這個許多步驟,從字串結尾位移開始搜尋位置:abs( start。) |
|
length | int |
要檢視的字元位置數目。 值為 -1 表示無限長度。 | |
occurrence | int |
發生次數。 預設值是 1。 |
傳回
以零起始的比對索引位置。
- 如果在字串中找不到相符專案,則傳回 -1。
null
如果:- start 小於 0。
- 發生次數 小於 0。
- length 小於 -1。
注意
- 不支援重疊的相符專案查閱。
- 正則表達式字串可能包含需要逸出或使用 @'' 字串常值的字元。
範例
print
idx1 = indexof_regex("abcabc", @"a.c"), // lookup found in input string
idx2 = indexof_regex("abcabcdefg", @"a.c", 0, 9, 2), // lookup found in input string
idx3 = indexof_regex("abcabc", @"a.c", 1, -1, 2), // there's no second occurrence in the search range
idx4 = indexof_regex("ababaa", @"a.a", 0, -1, 2), // Matches don't overlap so full lookup can't be found
idx5 = indexof_regex("abcabc", @"a|ab", -1) // invalid start argument
輸出
idx1 | idx2 | idx3 | idx4 | idx5 |
---|---|---|---|---|
0 | 3 | -1 | -1 |