using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @" <R-PORT-PROTOTYPE .*? <short-name>PQR</short-name>
(?:
(?:
(?(1) (?!) )
.*?
<V>
( .*? ) # (1)
</V>
.*?
<PARAMETER-REF [ ] DEST=""PARAMETER-DATA-PROTOTYPE""> .*? MNO1</PARAMETER-REF>
)
|
(?:
(?(2) (?!) )
.*?
<V>
( .*? ) # (2)
</V>
.*?
<PARAMETER-REF [ ] DEST=""PARAMETER-DATA-PROTOTYPE""> .*? MNO2</PARAMETER-REF>
)
){1,2}
.*
";
string substitution = @"MNO1=$1 , MNO2=$2";
string input = @" <R-PORT-PROTOTYPE **************>
<SHORT-NAME>PQR</SHORT-NAME>
<REQUIRED-COM-SPECS>
<PARAMETER-REQUIRE-COM-SPEC>
<APPLICATION-VALUE-SPECIFICATION>
<SHORT-LABEL>abc1</SHORT-LABEL>
<SW-VALUES-PHYS>
<V>80</V>
</SW-VALUES-PHYS>
</APPLICATION-VALUE-SPECIFICATION>
<PARAMETER-REF DEST=""PARAMETER-DATA-PROTOTYPE"">**************/MNO1</PARAMETER-REF>
</PARAMETER-REQUIRE-COM-SPEC>
<PARAMETER-REQUIRE-COM-SPEC>
<APPLICATION-VALUE-SPECIFICATION>
<SHORT-LABEL>abc2</SHORT-LABEL>
<SW-VALUES-PHYS>
<V>-80</V>
</SW-VALUES-PHYS>
</APPLICATION-VALUE-SPECIFICATION>
<PARAMETER-REF DEST=""PARAMETER-DATA-PROTOTYPE"">**************/MNO2</PARAMETER-REF>
</PARAMETER-REQUIRE-COM-SPEC>
</REQUIRED-COM-SPECS>
</R-PORT-PROTOTYPE>
";
RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline | RegexOptions.IgnoreCase;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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