using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<loc>[^>]*\K\d{6}(?=/</loc>)";
string input = @"<?xml version=""1.0"" encoding=""utf-8""?>
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">
<url>
<loc>https://somelink.com/category/building-materials/concrete/hand-tools/</loc>
<lastmod>2022-09-11T02:10:42+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/concrete/hand-tools/screws/screws-145890/</loc>
<lastmod>2022-09-11T02:11:06+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/concrete/hand-tools/screws/screws-145489/</loc>
<lastmod>2022-09-11T02:11:14+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/concrete/hand-tools/hammer/hammer-145488/</loc>
<lastmod>2022-09-11T02:10:42+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/inside/heating/floor-heating/pert-222-010274/</loc>
<lastmod>2022-09-11T02:11:06+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/paint/</loc>
<lastmod>2022-09-11T02:11:14+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/screws-and-nails/</loc>
<lastmod>2022-09-11T02:10:42+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/building-materials/concrete/power-toools/</loc>
<lastmod>2022-09-11T02:11:06+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/inside/heating/floor-heating/pert-182-010272/</loc>
<lastmod>2022-09-11T02:11:14+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/inside/heating/floor-heating/pert-202-010273/</loc>
<lastmod>2022-09-11T02:10:42+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/inside/bathroom/</loc>
<lastmod>2022-09-11T02:11:06+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://somelink.com/category/inside/pipes/draining-pipes-168544/</loc>
<lastmod>2022-09-11T02:11:14+02:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</xml>";
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