-1

I have a string that contains this group :

"|__|" or "|__|__|__|..."

With my pattern ([\|__|]{3,}) It will get the desired result but it captures different strings too, like this *"Name _____"*

Q: How can I capture only this kind of repeating group "|__|__|..." for this string ?

"Name _________ Age___ Postal Code|__|__|__|__|__|"
4

1 回答 1

2

[\|__|]是一个字符类,匹配一个 字符(|_\这里不需要,将被忽略)。

你需要一个小组

(\|__){3,}\|

(尽管严格来说,非捕获组将是这里最明智(但可读性稍差)的构造:)

(?:\|__){3,}\|
于 2013-07-17T09:50:35.283 回答