Get regex pattern
hi,
i want check "new incorrect id , label value element ref" in xml file using regex pattern ("\<ref id\=\"r|\"\>\r\n\<label\>|\<\/label\>") not worked.
regex regitem = new regex(@"\<ref id\=\"r|\"\>\r\n\<label\>|\<\/label\>"); please check regex , give me right pattern
for example: input: <ref-list id="appj.rl1"> <title>references for appendix j</title> <ref id="appj.r1"> <label>1</label> <citation citation-type="journal"> <ref id="appj.r4"> <label>4</label> output: <ref id="appj.r1"> <label>1</label> <ref id="appj.r4"> <label>4</label>
hi soniya,
find below, 1 posssible approach.
https://regex101.com/r/dq0iv7/1
string filepath = @"c:\msdn\textfile.txt"; stringbuilder sbfiletext1 = new stringbuilder(file.readalltext(filepath)); string pat01 = @"(<ref.*.r\d.>)|(<label>.+<\/label>)"; matchcollection matches = regex.matches(sbfiletext1.tostring(), pat01); foreach (match match in matches) { console.writeline(match.value); } console.readkey(); output:
<ref id="appj.r1"><label>1</label>
<ref id="appj.r4">
<label>4</label>
hope helps you.
thanks,
smsvikask
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment