Using regular expression to extract XML from an email message

I'm sending a plain-text email to a Sharepoint list that contains XML in the body. I'm fairly new with regular expressions, so I can't figure out how to do this:

When Sharepoint gets the email, it outputs it with the email headers included. So it's kinda like:

from: <blah@blah.com>
subject: Testing
x-date-msg: blah blah
some-other-random-stuff: blah blahb lbah

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
	<FieldType>
		<Field Name="ID">New</Field>
		<Field Name="Date">9/12/2010</Field>
		<Field Name="PubAndRun">ROP</Field>
	</FieldType>
</FieldTypes>

Open in new window


Could someone point me in the right direction of how I'd use a regular expression to extract just the body portion from this text?
GodsHandAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SyfAldeenConnect With a Mentor Commented:
This should do the trick!
It's better not to rely on the XML contents like "<FieldTypes>"

<\?xml[^>]+?\?>.*

Open in new window

RegEx.png
0
 
jeremycrussellCommented:
What OS/Tools would you be using to parse this?  essentially, you might use regex to catch the header data and rip it out, instead of trying to rip out the body.  The tools you plan to use will make a difference.
0
 
käµfm³d 👽Commented:
It should be as simple as:
<FieldTypes>.+?</FieldTypes>

Open in new window

0
 
SuperdaveCommented:
You will of course need to use the s flag, or preface the expression with (?s), for the above solution, so the . matches linefeeds.
0
 
käµfm³d 👽Commented:
>>  You will of course need to use the s flag, or preface the expression with (?s), ....

Unless of course the data is received with no newlines (i.e. one-line string); otherwise I agree :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.