<?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: Regexes in Depth: Advanced Quoted String Matching</title>
	<atom:link href="http://blog.stevenlevithan.com/archives/match-quoted-string/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com/archives/match-quoted-string</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Fri, 12 Mar 2010 14:48:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Craig</title>
		<link>http://blog.stevenlevithan.com/archives/match-quoted-string/comment-page-1#comment-45252</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Wed, 23 Dec 2009 07:06:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=4#comment-45252</guid>
		<description>I am trying to get a regular expression that will only remove double quotes between any html tag.

&lt;TABLE borderColor=#111111 cellSpacing=0 cellPadding=2 width= &quot;100%&quot; border=0&gt;I Like &quot;cheese&quot; 

Only want to remove quotes from width parameter.  Any help would be appreciated...</description>
		<content:encoded><![CDATA[<p>I am trying to get a regular expression that will only remove double quotes between any html tag.</p>
<p>&lt;TABLE borderColor=#111111 cellSpacing=0 cellPadding=2 width= &#8220;100%&#8221; border=0&gt;I Like &#8220;cheese&#8221; </p>
<p>Only want to remove quotes from width parameter.  Any help would be appreciated&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Simpson</title>
		<link>http://blog.stevenlevithan.com/archives/match-quoted-string/comment-page-1#comment-43432</link>
		<dc:creator>Kyle Simpson</dc:creator>
		<pubDate>Wed, 11 Nov 2009 03:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=4#comment-43432</guid>
		<description>I like this regex, pretty cool. However, one caveat to mention... in source code for a language like javascript that supports regex literals, this regex would match what it thinks are string literals inside a regex literal, which some might argue it should not.

currently working on my own set of code to properly recognize/tokenize string literals, regex literals, and single/multi-line comments from JS code, and I&#039;ve found that regex literals in particular throw lots of monkey wrench into the process.

The only way i&#039;ve found is a combination of limited regexes and a lot of stateful loop iteration processing to identify all the various cases where strings appear inside of regexes, or regexes appear inside of strings, or all the other weird cases that can happen. lots of fun, let me tell ya. :)</description>
		<content:encoded><![CDATA[<p>I like this regex, pretty cool. However, one caveat to mention&#8230; in source code for a language like javascript that supports regex literals, this regex would match what it thinks are string literals inside a regex literal, which some might argue it should not.</p>
<p>currently working on my own set of code to properly recognize/tokenize string literals, regex literals, and single/multi-line comments from JS code, and I&#8217;ve found that regex literals in particular throw lots of monkey wrench into the process.</p>
<p>The only way i&#8217;ve found is a combination of limited regexes and a lot of stateful loop iteration processing to identify all the various cases where strings appear inside of regexes, or regexes appear inside of strings, or all the other weird cases that can happen. lots of fun, let me tell ya. <img src='http://blog.stevenlevithan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manda</title>
		<link>http://blog.stevenlevithan.com/archives/match-quoted-string/comment-page-1#comment-41068</link>
		<dc:creator>Manda</dc:creator>
		<pubDate>Sat, 19 Sep 2009 07:49:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=4#comment-41068</guid>
		<description>In PHP, I&#039;m using this pattern :
&#039;/([\&quot;\&#039;])(?:.*[^\\\\]+)*(?:(?:\\\\{2})*)+\1/xU&#039;

Works great for me, even with multiple backslashed-backslashes, like :

name=&quot;manda yugana \\\&quot;gantenx\\\&quot; banget&quot;

or

name=&quot;manda yugana \\\\\&quot;gantenx\\\\\&quot; banget&quot;</description>
		<content:encoded><![CDATA[<p>In PHP, I&#8217;m using this pattern :<br />
&#8216;/([\"\'])(?:.*[^\\\\]+)*(?:(?:\\\\{2})*)+\1/xU&#8217;</p>
<p>Works great for me, even with multiple backslashed-backslashes, like :</p>
<p>name=&#8221;manda yugana \\\&#8221;gantenx\\\&#8221; banget&#8221;</p>
<p>or</p>
<p>name=&#8221;manda yugana \\\\\&#8221;gantenx\\\\\&#8221; banget&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://blog.stevenlevithan.com/archives/match-quoted-string/comment-page-1#comment-24959</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Mon, 21 Jul 2008 21:21:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=4#comment-24959</guid>
		<description>I am trying to adapt this in VB/VBScript to parse a dynamic sql result string for parameters.  I will then take each matched parameter and use a command parameter to help alleviate sql injection concerns.  I was getting tripped up with some of the more advanced input scenarios though, but now I think I have it straightened out.  Thought I&#039;d share it with you since I found your post here to do all the heavy lifting for me and others may find this useful.

Since VBS handles escaped quotes 2 double quotes I have modified the regex to handle those instead of javascript escaped characters.

&lt;pre class=&quot;code fixedHeight&quot;&gt;&lt;%
&#039;SQL query tests using parameters

&#039;@@@@@@@@@@@@@@@@@@@@     Functions     @@@@@@@@@@@@@@@@@@@@
	function ConvertToParams(sqlIn)
		retVal = sqlIn
		
		Set RegularExpressionObject = New RegExp
		
		With RegularExpressionObject
		.Pattern = &quot;([&quot;&quot;&#039;])(?:(?!\1)[^&quot;&quot;&quot;&quot;]&#124;&quot;&quot;&quot;&quot;.)*\1&quot;
		.IgnoreCase = True
		.Global = True
		End With
		
		Set expressionmatch = RegularExpressionObject.Execute(retVal)
		
		if expressionmatch.Count &gt; 0 Then
			For Each expressionmatched in expressionmatch
				Response.Write &quot;&lt;B&gt;&quot; &amp; expressionmatched.Value &amp; &quot;&lt;/B&gt; was matched at position &lt;B&gt;&quot; &amp; expressionmatched.FirstIndex &amp; &quot;&lt;/B&gt;&lt;BR&gt;&quot;
			Next
		end if
		
		ConvertToParams = retVal
	end function	
	
&#039;@@@@@@@@@@@@@@@@@@@@     End Functions     @@@@@@@@@@@@@@@@@@@@
%&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;&gt;
 &lt;head&gt;
 &lt;title&gt;Parameterized Queries Test&lt;/title&gt;
 &lt;script type=&quot;application/javascript&quot;&gt;
 &lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;p&gt;
 &lt;% 
	 
	 SQL = &quot;INSERT INTO dbo.TEST &quot; &amp; _
			&quot;(TEXT) &quot; &amp; _
			&quot;VALUES &quot; &amp; _
			&quot;(&quot;&quot;I would say that the &quot;&quot;&quot;&quot;preference&quot;&quot;&quot;&quot; is for a more open solution that will meet everyone&#039;s needs.  Wouldn&#039;t you agree with these thoughts I&#039;ve had?&quot;&quot;) &quot; &amp; _
			&quot;go &quot; &amp; _
			&quot;INSERT INTO dbo.TEST &quot; &amp; _
			&quot;(TEXT) &quot; &amp; _
			&quot;VALUES &quot; &amp; _
			&quot;(&quot;&quot;O&#039;brien&#039;s favorite pastime isn&#039;t listed although it &quot;&quot;&quot;&quot;should&quot;&quot;&quot;&quot; be&quot;&quot;) &quot; &amp; _
			&quot;go &quot;

	 response.write(&quot;SQL=&quot; &amp; SQL &amp; &quot;&lt;br /&gt;&lt;br /&gt;&quot; &amp;vbcrlf)	
	 response.write(ConvertToParams(SQL) &amp; &quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&quot; &amp;vbcrlf)		 
 %&gt;
 &lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I am trying to adapt this in VB/VBScript to parse a dynamic sql result string for parameters.  I will then take each matched parameter and use a command parameter to help alleviate sql injection concerns.  I was getting tripped up with some of the more advanced input scenarios though, but now I think I have it straightened out.  Thought I&#8217;d share it with you since I found your post here to do all the heavy lifting for me and others may find this useful.</p>
<p>Since VBS handles escaped quotes 2 double quotes I have modified the regex to handle those instead of javascript escaped characters.</p>
<pre class="code fixedHeight">&lt;%
'SQL query tests using parameters

'@@@@@@@@@@@@@@@@@@@@     Functions     @@@@@@@@@@@@@@@@@@@@
	function ConvertToParams(sqlIn)
		retVal = sqlIn

		Set RegularExpressionObject = New RegExp

		With RegularExpressionObject
		.Pattern = &quot;([&quot;&quot;'])(?:(?!\1)[^&quot;&quot;&quot;&quot;]|&quot;&quot;&quot;&quot;.)*\1&quot;
		.IgnoreCase = True
		.Global = True
		End With

		Set expressionmatch = RegularExpressionObject.Execute(retVal)

		if expressionmatch.Count &gt; 0 Then
			For Each expressionmatched in expressionmatch
				Response.Write &quot;&lt;B&gt;&quot; &amp; expressionmatched.Value &amp; &quot;&lt;/B&gt; was matched at position &lt;B&gt;&quot; &amp; expressionmatched.FirstIndex &amp; &quot;&lt;/B&gt;&lt;BR&gt;&quot;
			Next
		end if

		ConvertToParams = retVal
	end function	

'@@@@@@@@@@@@@@@@@@@@     End Functions     @@@@@@@@@@@@@@@@@@@@
%&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;&gt;
 &lt;head&gt;
 &lt;title&gt;Parameterized Queries Test&lt;/title&gt;
 &lt;script type=&quot;application/javascript&quot;&gt;
 &lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;p&gt;
 &lt;% 

	 SQL = &quot;INSERT INTO dbo.TEST &quot; &amp; _
			&quot;(TEXT) &quot; &amp; _
			&quot;VALUES &quot; &amp; _
			&quot;(&quot;&quot;I would say that the &quot;&quot;&quot;&quot;preference&quot;&quot;&quot;&quot; is for a more open solution that will meet everyone's needs.  Wouldn't you agree with these thoughts I've had?&quot;&quot;) &quot; &amp; _
			&quot;go &quot; &amp; _
			&quot;INSERT INTO dbo.TEST &quot; &amp; _
			&quot;(TEXT) &quot; &amp; _
			&quot;VALUES &quot; &amp; _
			&quot;(&quot;&quot;O'brien's favorite pastime isn't listed although it &quot;&quot;&quot;&quot;should&quot;&quot;&quot;&quot; be&quot;&quot;) &quot; &amp; _
			&quot;go &quot;

	 response.write(&quot;SQL=&quot; &amp; SQL &amp; &quot;&lt;br /&gt;&lt;br /&gt;&quot; &amp;vbcrlf)
	 response.write(ConvertToParams(SQL) &amp; &quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&quot; &amp;vbcrlf)
 %&gt;
 &lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blog.stevenlevithan.com/archives/match-quoted-string/comment-page-1#comment-14124</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 13 Feb 2008 00:38:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=4#comment-14124</guid>
		<description>A fair point, Ted. However, this post was born out of examples of using backreferences. I think the regex &lt;code&gt;([&quot;&#039;])(\\?+.)*?\1&lt;/code&gt; is quite pretty due to its brevity, but the rest of the regexes in this post are not great (this is one of my oldest posts here). If you really cared about performance you could unroll the loops, resulting in &lt;code&gt;&quot;[^&quot;\\]*(?:\\.[^&quot;\\]*)*&quot;&#124;&#039;[^&#039;\\]*(?:\\.[^&#039;\\]*)*&#039;&lt;/code&gt;. That&#039;s just as portable as what you posted if you take out the &lt;code&gt;?:&lt;/code&gt;s which create non-capturing groups.</description>
		<content:encoded><![CDATA[<p>A fair point, Ted. However, this post was born out of examples of using backreferences. I think the regex <code>(["'])(\\?+.)*?\1</code> is quite pretty due to its brevity, but the rest of the regexes in this post are not great (this is one of my oldest posts here). If you really cared about performance you could unroll the loops, resulting in <code>"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'</code>. That&#8217;s just as portable as what you posted if you take out the <code>?:</code>s which create non-capturing groups.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
