[quote=引用 4 楼 starfd 的回复:] (?<=A).*?(?=B)
Regex.Match(txt,@"(?<=A).*?(?=B)").Value
要分割字符串,使用 Split。例如首先以‘A' 字符分割,如果结果数组的 Length 返回>1,则说明有 'A'。那么可以接下来对数组第二个单元再以字符 'B' 分割,如果 Length >1 说明存在 'B',取数组的第一个单元,就是结果。
string str = "AdddddddB"; string pattern = "^A[^AB]*?B$"; var ismatch = Regex.IsMatch(str, pattern);
(?<=A).*?(?=B)
110,534
社区成员
642,575
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧