[英]C# RegEx, first match
I have next string: 我有下一个字符串:
String a = "someThing({Some text}); OtherStuff({Other text});";
I need to get the text included in '{' and '}' inside the 'someThing({...})'; 我需要将文本包含在“ someThing({...})”中的“ {”和“}”中;
I wrote: 我写:
var data = Regex.Match(a, @"(?<=someThing\(\{).*?(?=\}\)\;)", RegexOptions.Singleline).Groups[0].Value;
But as a result in data I get the whole string 'a'. 但是作为数据的结果,我得到了整个字符串“ a”。 My expected result - "{Some text}" 我的预期结果-“ {Some text}”
Thanks for any advance. 感谢您的任何进步。
The below regex would match zero or more characters but not of }
, or }
which was present just after to something({
以下正则表达式将匹配零个或多个字符,但不匹配}
或}
之后出现的}
something({
(?<=someThing\({)[^{}]*
If you want the output to contain {}
braces then you need to get out the opening curly bracket from lookbehind. 如果要让输出包含{}
大括号,则需要从后面查找出大括号。
(?<=someThing\(){[^{}]*}
(?<=someThing\()({[^{}}]*})
Try this.See demo. 试试看。看演示。
http://regex101.com/r/jT3pG3/31 http://regex101.com/r/jT3pG3/31
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.