<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Irregular Expressions &#187; regex xml</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/Irregular-Expressions/tag/regex-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/Irregular-Expressions</link>
	<description>Insight into current security related events and exploits, including virtualization security and tips.</description>
	<lastBuildDate>Sun, 28 Apr 2013 08:00:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Parsing XML with regular expressions &#8211; Part 2</title>
		<link>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-2/</link>
		<comments>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-2/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 02:14:36 +0000</pubDate>
		<dc:creator>Dan O'Connor</dc:creator>
				<category><![CDATA[parse xml]]></category>
		<category><![CDATA[perl regex]]></category>
		<category><![CDATA[regex group]]></category>
		<category><![CDATA[regex xml]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/Irregular-Expressions/?p=195</guid>
		<description><![CDATA[You cam also run into XML formatted like this. &#60;global&#62; &#60;pref name="trusted_ca" value="cacert.pem" /&#62; &#60;pref name="hide_toolbar" value="no" /&#62; &#60;pref name="hide_msglog" value="no" /&#62; &#60;pref name="auto_enable_new_plugins" value="yes" /&#62; &#60;pref name="use_client_cert" value="no" /&#62; &#60;pref name="nessusd_port" value="yes" /&#62; &#60;pref name="nessusd_user" value="openvas" /&#62; &#60;pref name="paranoia_level" value="yes" /&#62; &#60;pref name="targets" value="192.168.0.197" /&#62; &#60;pref name="name" value="Report 20100304-235837" /&#62; &#60;pref name="comment" value="" /&#62; [...]]]></description>
				<content:encoded><![CDATA[<p>You cam also run into XML formatted like this.</p>
<pre>                &lt;global&gt;
                        &lt;pref name="trusted_ca" value="cacert.pem" /&gt;
                        &lt;pref name="hide_toolbar" value="no" /&gt;
                        &lt;pref name="hide_msglog" value="no" /&gt;
                        &lt;pref name="auto_enable_new_plugins" value="yes" /&gt;
                        &lt;pref name="use_client_cert" value="no" /&gt;
                        &lt;pref name="nessusd_port" value="yes" /&gt;
                        &lt;pref name="nessusd_user" value="openvas" /&gt;
                        &lt;pref name="paranoia_level" value="yes" /&gt;
                        &lt;pref name="targets" value="192.168.0.197" /&gt;
                        &lt;pref name="name" value="Report 20100304-235837" /&gt;
                        &lt;pref name="comment" value="" /&gt;
                &lt;/global&gt;</pre>
<p>While this might look daunting it&#8217;s easy to pull anything that you want out with almost the same code as in the last example.</p>
<pre>foreach (@file) {
	if(/&lt;global&gt;/ ... /&lt;\/global&gt;/) {
		if(/&lt;pref name="(.+)" value="Report (.+)" \/&gt;/) {
			$name = $1;
			$report = $2;
		}
	}
}</pre>
<p>In a regex a &#8220;()&#8221; indicates a group, in perl you can refer to these groups by starting at 1. A &#8220;.&#8221; is a wild card match and a &#8220;+&#8221; states that it will match at least once but will continue to match if it can.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
