re = /(?:^|\n[[:space:]]+)<loc>[^<]*<\/loc>\n/m
str = '<?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>'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html