<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Regular Expressions Part VIII: [Square Brackets] and Dashes -</title>
	<atom:link href="http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/</link>
	<description>LunaMetric's blog on conversion rate and web analytics</description>
	<pubDate>Mon, 01 Dec 2008 23:44:24 +0000</pubDate>
	<generator>http://wordpress.org/</generator>
		<item>
		<title>By: Travholt</title>
		<link>http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/#comment-730</link>
		<dc:creator>Travholt</dc:creator>
		<pubDate>Wed, 15 Aug 2007 16:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://72.22.16.69/blog/?p=258#comment-730</guid>
		<description>Gah. I forgot the spam protection and my post disappeared into the great void upon pressing the back button. And it was such a good one! Well, here goes again, although I might never be able to match my previous attempt's level of wits ...

In RegExes, when you've made a match, you can access different parts of your matched data in different ways. For example, you can make a RegEx like this:

kung((foo) and (bar))barians

This would match the string "I like kungfoo and barbarians too!". The whole RE would match "kungfoo and barbarians", BUT the parentheses help you get at the interesting bits (like picking choc chips out of cookies!) easily, or, more correctly, make sure you're getting the choc chips from inside cookies instead of inside the trash bin.

In languages like Perl, which excels at REs, you do this through variables called $1, $2 and so on. The numbers correspond to the order in which the opening parentheses are found in the RE. GA has to distinguish between two different REs, so it calls these variables $A1, $A2 etc. for the first RE, and $B1, $B2 etc. for the second.

For the above example, $A1 would equal "foo and bar", while $A2 would contain "foo" and $A3 would be "bar".

I thought I'd keep the discussion here in the comments, as I am by no means an expert and others might be able to contribute too. But I love REs, and have been using them with great success and much saving of time or accomplishment of the otherwise practically impossible!</description>
		<content:encoded><![CDATA[<p>Gah. I forgot the spam protection and my post disappeared into the great void upon pressing the back button. And it was such a good one! Well, here goes again, although I might never be able to match my previous attempt&#8217;s level of wits &#8230;</p>
<p>In RegExes, when you&#8217;ve made a match, you can access different parts of your matched data in different ways. For example, you can make a RegEx like this:</p>
<p>kung((foo) and (bar))barians</p>
<p>This would match the string &#8220;I like kungfoo and barbarians too!&#8221;. The whole RE would match &#8220;kungfoo and barbarians&#8221;, BUT the parentheses help you get at the interesting bits (like picking choc chips out of cookies!) easily, or, more correctly, make sure you&#8217;re getting the choc chips from inside cookies instead of inside the trash bin.</p>
<p>In languages like Perl, which excels at REs, you do this through variables called $1, $2 and so on. The numbers correspond to the order in which the opening parentheses are found in the RE. GA has to distinguish between two different REs, so it calls these variables $A1, $A2 etc. for the first RE, and $B1, $B2 etc. for the second.</p>
<p>For the above example, $A1 would equal &#8220;foo and bar&#8221;, while $A2 would contain &#8220;foo&#8221; and $A3 would be &#8220;bar&#8221;.</p>
<p>I thought I&#8217;d keep the discussion here in the comments, as I am by no means an expert and others might be able to contribute too. But I love REs, and have been using them with great success and much saving of time or accomplishment of the otherwise practically impossible!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robbin</title>
		<link>http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/#comment-729</link>
		<dc:creator>Robbin</dc:creator>
		<pubDate>Wed, 15 Aug 2007 14:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://72.22.16.69/blog/?p=258#comment-729</guid>
		<description>I &lt;b&gt;think&lt;/b&gt; you need to do it like this:

term=([^&#038;]*)

(No ampersand at the end, else it matches to foo&#038; and then you have to go clean up all those &lt;b&gt;&#038;&lt;/b&gt; marks.  But, it looks like you are a RegExpert, and I just learn them so that I can do my job, so definitely - show me that I'm wrong.)

A few important thoughts:
1) You don't have to wait for data in your test profile, you can use the RegEx coach, or much easier, the Epikone tool. 
http://www.epikone.com/tools/regular-expression-filter-tester

2) I always learn things from readers like you!! I wish you would write out the whole logic here, so that everyone can learn this better. You can do it in a comment, and then I will go into the post and encourage people to read your comment. Or you can send me email, to my last name at my company name, and I will still edit the post and give you credit if you want.</description>
		<content:encoded><![CDATA[<p>I <b>think</b> you need to do it like this:</p>
<p>term=([^&#038;]*)</p>
<p>(No ampersand at the end, else it matches to foo&#038; and then you have to go clean up all those <b>&#038;</b> marks.  But, it looks like you are a RegExpert, and I just learn them so that I can do my job, so definitely - show me that I&#8217;m wrong.)</p>
<p>A few important thoughts:<br />
1) You don&#8217;t have to wait for data in your test profile, you can use the RegEx coach, or much easier, the Epikone tool.<br />
<a href="http://www.epikone.com/tools/regular-expression-filter-tester" rel="nofollow">http://www.epikone.com/tools/regular-expression-filter-tester</a></p>
<p>2) I always learn things from readers like you!! I wish you would write out the whole logic here, so that everyone can learn this better. You can do it in a comment, and then I will go into the post and encourage people to read your comment. Or you can send me email, to my last name at my company name, and I will still edit the post and give you credit if you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Travholt</title>
		<link>http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/#comment-728</link>
		<dc:creator>Travholt</dc:creator>
		<pubDate>Wed, 15 Aug 2007 10:02:23 +0000</pubDate>
		<guid isPermaLink="false">http://72.22.16.69/blog/?p=258#comment-728</guid>
		<description>Well, I think that you should mention the use of a carat within square brackets, because they're extremely useful for collecting characters within known delimiters. For example, to get just the search term in this url: www.mysite.com/search?term=foo&#38;order=desc you'd match against term=([^&#38;]*)&#38; meaning "get every character following "term=", but stop when an ampersand is encountered.

(Unless this doesn't work in GA, that is ... Which I'm currently awaiting data for in my test profile ...)</description>
		<content:encoded><![CDATA[<p>Well, I think that you should mention the use of a carat within square brackets, because they&#8217;re extremely useful for collecting characters within known delimiters. For example, to get just the search term in this url: <a href="http://www.mysite.com/search?term=foo&amp;order=desc" rel="nofollow">http://www.mysite.com/search?term=foo&amp;order=desc</a> you&#8217;d match against term=([^&amp;]*)&amp; meaning &#8220;get every character following &#8220;term=&#8221;, but stop when an ampersand is encountered.</p>
<p>(Unless this doesn&#8217;t work in GA, that is &#8230; Which I&#8217;m currently awaiting data for in my test profile &#8230;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
