using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(\d.+)(?=\s*\"" Unit=\""W\"" Type=\""AC_Power\"")";
string input = @"<Measurements>
<Measurement Value=""237.6"" Unit=""V"" Type=""AC_Voltage""/>
<Measurement Value=""9.828"" Unit=""A"" Type=""AC_Current""/>
<Measurement Value=""2344.7"" Unit=""W"" Type=""AC_Power""/>
<Measurement Value=""2343.4"" Unit=""W"" Type=""AC_Power_fast""/>
<Measurement Value=""50.003"" Unit=""Hz"" Type=""AC_Frequency""/>
<Measurement Value=""294.4"" Unit=""V"" Type=""DC_Voltage1""/>
<Measurement Value=""171.3"" Unit=""V"" Type=""DC_Voltage2""/>
<Measurement Value=""8.056"" Unit=""A"" Type=""DC_Current1""/>
<Measurement Unit=""A"" Type=""DC_Current2""/>
<Measurement Value=""343.8"" Unit=""V"" Type=""LINK_Voltage""/>
<Measurement Unit=""W"" Type=""GridPower""/>
<Measurement Unit=""W"" Type=""GridConsumedPower""/>
<Measurement Unit=""W"" Type=""GridInjectedPower""/>
<Measurement Unit=""W"" Type=""OwnConsumedPower""/>
<Measurement Value=""100.0"" Unit=""%"" Type=""Derating""/>
</Measurements>
</Device>
</root>";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx