[英]Get string between with regex
I have string like:我有这样的字符串:
<plaintext>10/2 (2×5 + (10 - 1)×2)</plaintext>
</subpod>
<expressiontypes count='1'>
<expressiontype name='Default' />
</expressiontypes>
</pod>
<pod title='Exact result'
scanner='Rational'
id='Result'
position='200'
error='false'
numsubpods='2'
primary='true'>
<subpod title=''>
<plaintext>140</plaintext>
</subpod>
<plaintext>Simplify the following:
(10 (2×5 + (10 - 1) 2))/2
(10 (2×5 + (10 - 1) 2))/2 = (10 (2×5 + (10 - 1) 2))/2:
(10 (2×5 + (10 - 1) 2))/2
10/2 = (2×5)/2 = 5:
5 (2×5 + (10 - 1) 2)
10 - 1 = 9:
5 (2×5 + 9×2)
2×5 = 10:
5 (10 + 9×2)
9×2 = 18:
5 (18 + 10)
| 1 | 8
+ | 1 | 0
| 2 | 8:
5×28
5×28 = 140:
Answer: |
| 140</plaintext>
And i want to get string between these two tags <plaintext>
, </plaintext>
My code so far我想在这两个标签之间获取字符串<plaintext>
, </plaintext>
我的代码到目前为止
StringBuilder stringBuilder = new StringBuilder();
Regex regex = new Regex(@"<plaintext>(.*?)</plaintext>");
foreach (Match match in regex.Matches(here is string above)
stringBuilder.Append(match.Groups[1].Value);
But my regex get only string in same line but when <plaintext>
, </plaintext>
tags are on different lines - cant parse it.但是我的正则表达式只在同一行中获取字符串,但是当<plaintext>
, </plaintext>
标签位于不同的行时 - 无法解析它。
You need to add RegexOptions.Singleline
to your regex-arguments like this.您需要像这样将RegexOptions.Singleline
添加到您的正则表达式参数中。
var regex = new Regex(@"<plaintext>(.*?)</plaintext>",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
Then it will capture everything except newlines.然后它将捕获除换行符之外的所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.