-1

I am editing a KML file that has info in it like:

        <name>some name</name>
        <description> some description and search target</description>
        <styleUrl>#icon-960-DB4436</styleUrl>
        <Point>
          <coordinates>
            34.7661563,32.059198,0
          </coordinates>
        </Point>
      </Placemark> 

I am trying to use a regex that will capture all the info from when begins until ends if some target string is present in the tag.

I tried this <placemark>.*?search target.*?</placemark>

but ofcourse it will capture more than I need.

some help please?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Amir Yaari
  • 43
  • 4
  • Is your sample missing the opening `` tag? Are the tags really a mixture of case styles (some all lowercase, some leading caps)? – Bohemian May 01 '21 at 17:28

1 Answers1

1

Qualify dot with a negative lookahead for </Placemark> to restrict searches to within such a tag.

To find the text DB4436 (from your example) use:

<Placemark>((?!<\/Placemark>).)*DB4436((?!<\/Placemark>).)*<\/Placemark>

with the DOTALL flag on (you haven't indicated the language/tool you're using, so I can't show how to specify that - it varies).

See live demo.

Bohemian
  • 412,405
  • 93
  • 575
  • 722