source xml string
<w:tc>
<w:tcPr>
<w:tcW w:w="1870" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="4A2404F3" w14:textId="6CC57F74" w:rsidR="00B721B4" w:rsidRDefault="00B721B4">
<w:r>
<w:t>{{</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>CreateDate</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:t>}}</w:t>
</w:r>
</w:p>
</w:tc>
expect
<w:r>
<w:t>2022-09-20</w:t>
</w:r>
I tried to use below regex and C# code to replace but it did not work.online demo
void Main()
{
var input = @"<w:r>
<w:t>{{</w:t>
</w:r>
<w:proofErr w:type=""spellStart""/>
<w:r>
<w:t>CreateDate</w:t>
</w:r>
<w:proofErr w:type=""spellEnd""/>
<w:r>
<w:t>}}</w:t>
</w:r>";
var pattern = @"\{\{*CreateDate*\}\}";
var output = Regex.Replace(input,pattern,"2022-09-20");
Console.WriteLine(output);
}
I think *
between {}
can replace it, could friends give me idea about my mistakes, really appreciate!
Update2:
I tried to use \{\{.+Company_Name.+\}\}
but it get full string between first {{
and last }}
, online demo