Regular expression for match content between ('<' or "></") and ('>')

Asked

Viewed 38 times

0

From text in XML format:

<shipto
 attr="xpto">
 <name>Nordmann</name>
 <address>Langgt 23</address>
 <city>4000 Stavanger</city>
</shipto>

I want to get the match of:

  1. <shipto attr="xpto">
  2. <name>Nordmann</name>
  3. <address>Langgt 23</address>
  4. <city>4000 Stavanger</city>
  5. </shipto>

That is, the content between < or ></ and the char >.

  • If possible, please [Edit] the question and add the language you are using, because each one implements regex in one way and what works in one may not work in the other (and also put what you have tried). Anyway, regex is not always the best tool to mess with XML/HTML, usually it is better to use a lib or parser specific (that most languages have)

  • Besides, if you just want "what’s in between < and >", then <name> and </name> should not be in pouch separate? Or have different rules for when the tag has other tags inside it? When [Edit] the question, take the opportunity to clarify these criteria...

  • thanks, in fact what I needed was a parser: parseFromString("...", "text/xml");

1 answer

0

I used a parser to generate an object that allows working with the text in XML format:

const parser = new DOMParser();
const xmlDoc = parser.parseFromString(this.mockXml, "text/xml");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.