我想將字串的 REGEX 放在一起:
/maps/basic/5/16/12.png?key=xxx
我在這里想要實作的是,如果字串(URI)在 2 個單詞之后包含 3 個數字,我的條件將為 TRUE:
/word/word/number/number/number*
uj5u.com熱心網友回復:
您可以使用以下模式:
^(\/[a-zA-Z] \/[a-zA-Z] \/[0-9] \/[0-9] \/[0-9] )(\S.*)$
您的示例的結果將是:
- 第一組比賽:
/maps/basic/5/16/12 - 第 2 組匹配,其余字串:
.png?key=xxx
uj5u.com熱心網友回復:
嘗試這個:
^\/[a-zA-Z] \/[a-zA-Z] \/\d \/\d \/\d .*
^ mathes the beginning of the string
\/[a-zA-Z] matches the first word
\/[a-zA-Z] matches the second word
\/\d \/\d \/\d matches the three numbers
.* matches anything after the numbers
僅當 URL 以兩個單詞開頭并后跟三個(或更多)單詞以及之后的任何內容時,它才會匹配該 URL。
在這里測驗:https ://regex101.com/r/mjWNUb/1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/427093.html
標籤:正则表达式
