<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Fun With .NET Regex Balancing Groups</title>
	<atom:link href="http://blog.stevenlevithan.com/archives/balancing-groups/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com/archives/balancing-groups</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 02:09:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Anuj</title>
		<link>http://blog.stevenlevithan.com/archives/balancing-groups/comment-page-1#comment-123875</link>
		<dc:creator>Anuj</dc:creator>
		<pubDate>Tue, 09 Aug 2011 01:46:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/balancing-groups#comment-123875</guid>
		<description>I had an xml file with certain tag

&lt;xyz&gt; 1800 &lt; 3944877 &lt;/xyz&gt;

in this the less than sign is causing problem to read the xml file so I was thinking to use regex to find the less than sign and replace it.
I am using c#

Can any tell me the regex or is there any other way i can do it

I write this :
(&lt;[^]*?&gt;).*(&lt;).*?(&lt;[^]*?&gt;)
but it holds good till each tag is separated with new line.</description>
		<content:encoded><![CDATA[<p>I had an xml file with certain tag</p>
<p>&lt;xyz&gt; 1800 &lt; 3944877 &lt;/xyz&gt;</p>
<p>in this the less than sign is causing problem to read the xml file so I was thinking to use regex to find the less than sign and replace it.<br />
I am using c#</p>
<p>Can any tell me the regex or is there any other way i can do it</p>
<p>I write this :<br />
(&lt;[^]*?&gt;).*(&lt;).*?(&lt;[^]*?&gt;)<br />
but it holds good till each tag is separated with new line.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anuj</title>
		<link>http://blog.stevenlevithan.com/archives/balancing-groups/comment-page-1#comment-123874</link>
		<dc:creator>Anuj</dc:creator>
		<pubDate>Tue, 09 Aug 2011 01:44:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/balancing-groups#comment-123874</guid>
		<description>I had an xml file with certain tag

1800 &lt; 3944877

in this the less than sign is causing problem to read the xml file so I was thinking to use regex to find the less than sign and replace it.
I am using c#

Can any tell me the regex or is there any other way i can do it

I write this :
(&lt;[^]*?&gt;).*(&lt;).*?(&lt;[^]*?&gt;)
but it holds good till each tag is separated with new line.</description>
		<content:encoded><![CDATA[<p>I had an xml file with certain tag</p>
<p>1800 &lt; 3944877</p>
<p>in this the less than sign is causing problem to read the xml file so I was thinking to use regex to find the less than sign and replace it.<br />
I am using c#</p>
<p>Can any tell me the regex or is there any other way i can do it</p>
<p>I write this :<br />
(&lt;[^]*?&gt;).*(&lt;).*?(&lt;[^]*?&gt;)<br />
but it holds good till each tag is separated with new line.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Hall</title>
		<link>http://blog.stevenlevithan.com/archives/balancing-groups/comment-page-1#comment-77199</link>
		<dc:creator>Dave Hall</dc:creator>
		<pubDate>Thu, 10 Feb 2011 05:42:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/balancing-groups#comment-77199</guid>
		<description>I discovered this page as well as &#039;Expresso&#039; tonight and used it to learn about &quot;Balancing Groups&quot;. 

I used it to work out a moderately complex expression to validate a US phone number with optional parenthesis around the area code. It worked great in all of my Expresso and C# tests. The problem I ran into is when I tried to use the same expression in a javascript function to validate a phone number in a form on a web page. The expression throws a javascript exception in the RegEx constructor. It&#039;s apparently not valid in Javascript. I tried whittling it back down to basics in Javascript and I can&#039;t even figure out how to get the basic named matched sub-expressions working in Javascript. I&#039;m not going to list all the Javascript variants that I tried, but I&#039;ll mention the .Net version that I was able to get working. I was wonderng if you (or anyone) might be up for the challenge of helping me figure out how to translate this to a Javascript equivalent regex or if anyone could direct me to a good regex forum where I can get some help on this.

Here are my test cases and the regex itself. 

These values should (and do) match:
&quot;(555) 555-5555&quot;
&quot;(555)-555-5555&quot;
&quot;(555)555-5555&quot;
&quot;555 555-5555&quot;
&quot;555-555-5555&quot;
&quot;&quot;

These values should NOT (and don&#039;t) match:
&quot;(055) 555-5555&quot;
&quot;(155) 555-5555&quot;
&quot;(555) 055-5555&quot;
&quot;(555) 155-5555&quot;
&quot;(555 555-5555&quot;
&quot;555) 555-5555&quot;
&quot;555)555-5555&quot;
&quot;555555-5555&quot;

Here&#039;s the expression:
Note that neither area code (npa) nor the first 3 digit of the local number (nxx) is allowed to start with 0 or 1. That&#039;s the reason for using &quot;[2-9]\d\d&quot; instead of &quot;\d{3}&quot; as in many phone number regex examples.

Note also that the RegEx needs the IgnorePatternWhitespace option as it&#039;s shown here, but it could be reduced to a single line that doesn&#039;t need that option if you&#039;re willing to sacrifice readability.

&quot;^1?
(?:
(?&#039;open&#039;\()?
(?&#039;npa&#039;(?:[2-9]\d\d)?)
(?&#039;close-open&#039;\))?
(?(open)(?!))
(?:
    (?:\s)
    &#124;
    (?:-)
    &#124;
    (?&lt;=\))
)
(?&#039;nxx&#039;(?:[2-9]\d\d))
-
(?&#039;line&#039;\d{4})
)?
$&quot;

Thanks,
Dave</description>
		<content:encoded><![CDATA[<p>I discovered this page as well as &#8216;Expresso&#8217; tonight and used it to learn about &#8220;Balancing Groups&#8221;. </p>
<p>I used it to work out a moderately complex expression to validate a US phone number with optional parenthesis around the area code. It worked great in all of my Expresso and C# tests. The problem I ran into is when I tried to use the same expression in a javascript function to validate a phone number in a form on a web page. The expression throws a javascript exception in the RegEx constructor. It&#8217;s apparently not valid in Javascript. I tried whittling it back down to basics in Javascript and I can&#8217;t even figure out how to get the basic named matched sub-expressions working in Javascript. I&#8217;m not going to list all the Javascript variants that I tried, but I&#8217;ll mention the .Net version that I was able to get working. I was wonderng if you (or anyone) might be up for the challenge of helping me figure out how to translate this to a Javascript equivalent regex or if anyone could direct me to a good regex forum where I can get some help on this.</p>
<p>Here are my test cases and the regex itself. </p>
<p>These values should (and do) match:<br />
&#8220;(555) 555-5555&#8243;<br />
&#8220;(555)-555-5555&#8243;<br />
&#8220;(555)555-5555&#8243;<br />
&#8220;555 555-5555&#8243;<br />
&#8220;555-555-5555&#8243;<br />
&#8220;&#8221;</p>
<p>These values should NOT (and don&#8217;t) match:<br />
&#8220;(055) 555-5555&#8243;<br />
&#8220;(155) 555-5555&#8243;<br />
&#8220;(555) 055-5555&#8243;<br />
&#8220;(555) 155-5555&#8243;<br />
&#8220;(555 555-5555&#8243;<br />
&#8220;555) 555-5555&#8243;<br />
&#8220;555)555-5555&#8243;<br />
&#8220;555555-5555&#8243;</p>
<p>Here&#8217;s the expression:<br />
Note that neither area code (npa) nor the first 3 digit of the local number (nxx) is allowed to start with 0 or 1. That&#8217;s the reason for using &#8220;[2-9]\d\d&#8221; instead of &#8220;\d{3}&#8221; as in many phone number regex examples.</p>
<p>Note also that the RegEx needs the IgnorePatternWhitespace option as it&#8217;s shown here, but it could be reduced to a single line that doesn&#8217;t need that option if you&#8217;re willing to sacrifice readability.</p>
<p>&#8220;^1?<br />
(?:<br />
(?&#8217;open&#8217;\()?<br />
(?&#8217;npa&#8217;(?:[2-9]\d\d)?)<br />
(?&#8217;close-open&#8217;\))?<br />
(?(open)(?!))<br />
(?:<br />
    (?:\s)<br />
    |<br />
    (?:-)<br />
    |<br />
    (?&lt;=\))<br />
)<br />
(?&#039;nxx&#039;(?:[2-9]\d\d))<br />
-<br />
(?&#039;line&#039;\d{4})<br />
)?<br />
$&quot;</p>
<p>Thanks,<br />
Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stoive</title>
		<link>http://blog.stevenlevithan.com/archives/balancing-groups/comment-page-1#comment-59900</link>
		<dc:creator>stoive</dc:creator>
		<pubDate>Mon, 20 Sep 2010 07:07:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/balancing-groups#comment-59900</guid>
		<description>This is exactly what I needed. Balancing groups is the one part of .NET regex I hadn&#039;t used before and this explains exactly what I needed to move my parser forward, thank you!</description>
		<content:encoded><![CDATA[<p>This is exactly what I needed. Balancing groups is the one part of .NET regex I hadn&#8217;t used before and this explains exactly what I needed to move my parser forward, thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: .NET Regex Recursive Patterns &#124; The Largest Forum Archive</title>
		<link>http://blog.stevenlevithan.com/archives/balancing-groups/comment-page-1#comment-56507</link>
		<dc:creator>.NET Regex Recursive Patterns &#124; The Largest Forum Archive</dc:creator>
		<pubDate>Wed, 28 Jul 2010 04:52:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/balancing-groups#comment-56507</guid>
		<description>[...] is no recursive pattern in .NET. Instead, it provides balancing groups for stack-based manipulation for matching simple nested [...]</description>
		<content:encoded><![CDATA[<p>[...] is no recursive pattern in .NET. Instead, it provides balancing groups for stack-based manipulation for matching simple nested [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

