﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Rob Kitson commented on Challenge: The regex that doesn’t match</title><description>Ooops, didn't see James' comment above... and it looks like it works.
  
  
The Regex.Escape() method does pretty much what I described above.  From the docs: "Escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $,., #, and white space) by replacing them with their escape codes."
  
  
That's handy.
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment19</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment19</guid><pubDate>Thu, 21 May 2009 22:45:35 GMT</pubDate></item><item><title>Rob Kitson commented on Challenge: The regex that doesn’t match</title><description>Don't know if you're still having issues here, but it looks like you need to escape the '*' and '.' characters in the pattern.  Also, you probably need to compact the whitespace in the pattern to as few as possible, then replace them with \s*
  
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment18</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment18</guid><pubDate>Thu, 21 May 2009 22:40:29 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: The regex that doesn’t match</title><description>Cory,
  
Yes, I know about that, but since this is a WPF app, and Mono doesn't have that, I don't worry too much about it
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment17</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment17</guid><pubDate>Tue, 12 May 2009 05:45:50 GMT</pubDate></item><item><title>Cory Foy commented on Challenge: The regex that doesn’t match</title><description>FYI - I know the multiline syntax is handy from a readability perspective, but tests like that may not pass on Mono/Linux or any other OS that doesn't use \r\n as the line terminator:
  
  
[www.cornetdesign.com/.../...nvironmentnewline.html](http://www.cornetdesign.com/2006/03/importance-of-systemenvironmentnewline.html)  
  
To get it to pass, you'd have to recompile on the platform. Well, unless you *are* developing this on Mono/Linux, but I don't think that's the case. :)
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment16</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment16</guid><pubDate>Tue, 12 May 2009 03:56:31 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: The regex that doesn’t match</title><description>Why would we care about the regex when the entire principle this is based on is a big hairy WTF?
  
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment15</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment15</guid><pubDate>Mon, 11 May 2009 21:22:36 GMT</pubDate></item><item><title>Bertrand Le Roy commented on Challenge: The regex that doesn’t match</title><description>Cool. That part does look convoluted :)
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment14</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment14</guid><pubDate>Mon, 11 May 2009 20:22:22 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: The regex that doesn’t match</title><description>Bertrand,
  
Well, when you only see a very small part, it is not surprising
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment13</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment13</guid><pubDate>Mon, 11 May 2009 20:17:33 GMT</pubDate></item><item><title>Michael Morton commented on Challenge: The regex that doesn’t match</title><description>@Chris I was only providing one example of what would be escaped.  As Sergey and bobo mentioned, the comment tags also cause an issue because '*' is a regex quantifier, and as such, is escaped by Regex.Escape as well.
  
  
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment12</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment12</guid><pubDate>Mon, 11 May 2009 19:19:02 GMT</pubDate></item><item><title>Chris Martin commented on Challenge: The regex that doesn’t match</title><description>            const string EXPECTED = @"Cached query: 
  
SELECT this_.Id             as Id5_0_,
  
       this_.Title          as Title5_0_,
  
       this_.Subtitle       as Subtitle5_0_,
  
       this_.AllowsComments as AllowsCo4_5_0_,
  
       this_.CreatedAt      as CreatedAt5_0_
  
FROM   Blogs this_
  
WHERE  this_.Title = 'The lazy blog' /* @p0 */
  
       and this_.Id = 1 /* @p1 */";
  
  
            string pattern = Regex.Escape(EXPECTED).Replace("5_", @"\d+_");
  
  
            Assert.True(Regex.IsMatch(EXPECTED, pattern));
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment11</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment11</guid><pubDate>Mon, 11 May 2009 19:11:10 GMT</pubDate></item><item><title>Bryan commented on Challenge: The regex that doesn’t match</title><description>There isn't anything wrong with the string, but that regex will never work, as it's going to change all the digits to 5.  Should be this: @"\d+_(?=0)"  That does a lookahead and only matches digits followed by an _ then a 0.  The 0 is then not part of the grouping and so won't be changed.
  
  
It doesn't make sense, why would you want to do that anyway?
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment10</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment10</guid><pubDate>Mon, 11 May 2009 19:07:53 GMT</pubDate></item><item><title>James commented on Challenge: The regex that doesn’t match</title><description>Regex.IsMatch(expected,Regex.Escape(expected).Replace("5_", @"\d+_"))
  
passes
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment9</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment9</guid><pubDate>Mon, 11 May 2009 19:05:30 GMT</pubDate></item><item><title>Bertrand Le Roy commented on Challenge: The regex that doesn’t match</title><description>Aren't tests supposed to be readable? I have no idea what this is supposed to do from staring at the code. Might be just me though.
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment8</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment8</guid><pubDate>Mon, 11 May 2009 19:04:16 GMT</pubDate></item><item><title>Fredy commented on Challenge: The regex that doesn’t match</title><description>So, is Replace doing something funny to the asterisk or what?...
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment7</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment7</guid><pubDate>Mon, 11 May 2009 18:40:12 GMT</pubDate></item><item><title>Joel commented on Challenge: The regex that doesn’t match</title><description>It's a problem with the comment tags in the SQL statement.  Remove the comments and the regular expression passes.
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment6</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment6</guid><pubDate>Mon, 11 May 2009 18:17:29 GMT</pubDate></item><item><title>bobo commented on Challenge: The regex that doesn’t match</title><description>Maybe Regex.Escape before you do your Replace might help...
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment5</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment5</guid><pubDate>Mon, 11 May 2009 18:08:57 GMT</pubDate></item><item><title>bobo commented on Challenge: The regex that doesn’t match</title><description>it's the /* */ comments...
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment4</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment4</guid><pubDate>Mon, 11 May 2009 18:03:44 GMT</pubDate></item><item><title>Sergey Koshcheyev commented on Challenge: The regex that doesn’t match</title><description>But regex "/* " won't match string "/* ".
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment3</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment3</guid><pubDate>Mon, 11 May 2009 18:03:42 GMT</pubDate></item><item><title>Chris commented on Challenge: The regex that doesn’t match</title><description>Michael: '.' will match any single character, so that will still work; it will just match more than expected.
  
  
I might guess that the newlines are confusing the regex engine.
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment2</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment2</guid><pubDate>Mon, 11 May 2009 17:49:50 GMT</pubDate></item><item><title>Michael Morton commented on Challenge: The regex that doesn’t match</title><description>Regex.IsMatch(expected, Regex.Escape(expected).Replace(@"5_", @"\d+_"))
  
  
The query contains regex characters which need to be escaped (i.e. '.').
  
  
It's a bit messy ... if this is going to be used a lot, would probably be good to replace the whitespace with '\s+', etc.
</description><link>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment1</link><guid>http://ayende.com/4005/challenge-the-regex-that-doesn-t-match#comment1</guid><pubDate>Mon, 11 May 2009 17:45:52 GMT</pubDate></item></channel></rss>