[英]Capturing text between two words using a regular expression
I am trying to get the text in between two keywords using a regular expression in CSharp. 我试图在CSharp中使用正则表达式在两个关键字之间获取文本。 Although I already found a topic with the same heading, that one was about finding the text in between square brackets, which is rather easy, since you can use
\\[(?<blah>[^\\]]+?)\\]
to do this. 虽然我已经找到了一个带有相同标题的主题,但那个是关于在方括号之间找到文本,这很容易,因为你可以使用
\\[(?<blah>[^\\]]+?)\\]
来做这个。
What I am trying to do is finding the words Matched text 123./!
我想要做的是找到
Matched text 123./!
in UnMatched text 123./!team
. 在
UnMatched text 123./!team
。 So my delimiters are Un
and team
. 所以我的分隔符是
Un
和team
。 If I would build my RegEx the way I am used to, I would need to do three parts again: Un
for the start delimiter at the beginning, team
for the end delimiter at the end and a group (?<blah>...+?)
which says "Anything but the string team
". 如果我按照我习惯的方式构建我的RegEx,我需要再做三个部分:
Un
用于开头的开始分隔符, team
用于结束分隔符和一个组(?<blah>...+?)
其中写着“除了弦team
任何东西”。 But I dunno how to express this in regular expressions. 但我不知道如何在正则表达式中表达这一点 。
Is there a way to say "not this string" instead of "not one of those characters"? 有没有办法说“不是这个字符串”而不是“不是其中一个字符”? Also since I don't know about differences between implementations of Regular Expressions: I am using
System.Text.RegularExpressions.RegEx
of the .NET-Framework to parse them, so of course the sample should be working with this implementations. 此外,因为我不知道正则表达式的实现之间的差异:我使用.NET-Framework的
System.Text.RegularExpressions.RegEx
来解析它们,所以当然样本应该使用这个实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.