說明
(?:[*]*[|]){4,}
這個正則表達式將執行以下操作:
- 查找是由
*
和|
字符
- 子需要串到至少包含四個
|
字符
- 允許該子有任意數量的
*
個字符
實施例
現場演示
https://regex101.com/r/mJ4nY4/2
示例文本
|||||||||||||||
|***|*||******|
|||*****************|
|||
|?|*|*|
|||?|
樣品匹配
|||||||||||||||
|***|*||******|
|||*****************|
說明
NODE EXPLANATION
----------------------------------------------------------------------
(?: group, but do not capture (at least 4
times (matching the most amount
possible)):
----------------------------------------------------------------------
[*]* any character of: '*' (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
[|] any character of: '|'
----------------------------------------------------------------------
){4,} end of grouping
----------------------------------------------------------------------
備用
如果你不想要捕獲的領先*
爲字符串*|||**|
,然後你可以用這句話
[|](?:[*]*[|]){3,}
例
現場演示
https://regex101.com/r/yN6wK2/1
您可以測試你的正則表達式在這裏:http://regexr.com/。還有一個有用的正則表達式cheatsheet。 – Danibix