问题描述
我试图让使用C#一个正则表达式两个关键字之间的文本。
虽然我已经找到一个话题相同的标题,一个是关于寻找在方括号中的文字,这是相当容易的,因为你可以使用 \ [(LT;等等> ;。[^ \] +)\]
来做到这一点。
I am trying to get the text in between two keywords using a regular expression in 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.
我所试图做的是找到的话匹配的文本123 ./!
在无与伦比的文本123 ./!团队
。所以,我的分隔符联合国
和团队
。如果我将建立我的正则表达式我习惯的方式,我需要再做三个部分:联合国
为开头的起始分隔符,团队
在年底结束分隔符和一组(其中p?等等> ... +)
它说什么,但字符串团队
。但我不知道如何表达的这个的正则表达式。
What I am trying to do is finding the words Matched text 123./!
in UnMatched text 123./!team
. So my delimiters are Un
and 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
". But I dunno how to express this in regular expressions.
有没有办法说没有这串而不是没有一个人这些字符?
也因为我不知道正则表达式的实现之间的差异:我使用 System.Text.RegularExpressions.RegEx
的.NET的框架来分析的他们,所以当然的样品应与此实现合作。
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.
推荐答案
您可以使用此语法
(?s)(?<=start_delim).+?(?=end_delim)
只需更换 start_delim
和 end_delim
的要求。访问在这方面的更多信息。
just replace start_delim
and end_delim
as required. Visit here for more information in this regard.
这篇关于使用正则表达式两个词之间捕获文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!