0

Lets say I have the following XML

<Monkey xmlns="http://myurlisrighthereheremonkey.com/monkeynamespace">
 <foodType>
  <vegtables>
   <carrots>1</carrots>
  </vegtables>
 <foodType>   
</Monkey>

Now the service im using already has the root level element and name space. so I really just need:

 <foodType>
  <vegtables>
   <carrots>1</carrots>
  </vegtables>
 <foodType>  

Is there a regex I can use that generically removes both the top level opening and closing tags? By generic I mean that it doesn't have to start with the type Monkey.

Thanks in advance!

1
  • What language do you use? Commented Apr 25, 2014 at 13:22

1 Answer 1

2

You can match the following regex:

^<[^>]+>(.*)<\/\w+>$

and replace with the first captured group \1 or $1

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.