Solved

Using regular expression to extract XML from an email message

Posted on 2010-08-19
5
632 Views
Last Modified: 2013-11-11
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?
0
Comment
Question by:GodsHand
5 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33480711
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33481256
It should be as simple as:
<FieldTypes>.+?</FieldTypes>

Open in new window

0
 
LVL 13

Expert Comment

by:Superdave
ID: 33482112
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33482143
>>  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
 
LVL 4

Accepted Solution

by:
SyfAldeen earned 500 total points
ID: 33483220
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML XSLT If loop 4 29
REXEX help Part 2 2 38
Migration from SQL server to oracle (XML input) 4 23
Help with a Python script converting xml to csv 3 14
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question