Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
string x = "[string] two[string] (1thing)"; Regex sort1 = new Regex(@"\[(.*?)\]"); MatchCollection sortOpen = sort1.Matches(x); foreach (Match y in sortOpen) { .. }
带括号返回:如何返回没有用于排序的标签的字符串?
您可以使用
(?<=\[)(.*?)(?=\])
在 .NET 中。(?<=expression)匹配expression 前缀但将其从捕获中排除,同时(?=expression)匹配expression 后缀但将其从捕获中排除。
(?<=expression)
expression
(?=expression)