Skip to main content

Posts

Showing posts from September, 2012

C# Strings and Code Generation Bug Fixed

It was brought to my attention yesterday that there was a bug with the C# code generation feature inside Regex Hero.   Thanks Blake for pointing it out .  It turns out that I had made a stupid mistake in the way I was adding \r and \n to the string.  I mostly rely on the @"string" literals because they're convenient and generally cleaner for what I need to do.  But of course, the escaped notations \r and \n don't work inside those strings. So this has been updated this morning.  From now on Regex Hero will generate C# strings more like this... @"line1" + "\n" + @"line2"

Optimized Memory Consumption

Today's update includes a minor change to the custom undo/redo system in all of the textboxes within Regex Hero.  They will now only store history on the OnKeyUp event, rather than storing history for every change.  In other words, if you hold down a key on the keyboard for a long time it's not going to store history for every single character individually anymore. This is a subtle difference, but in real world usage this should have a substantial impact on how much memory is used to hold the text history.

ASP.NET MVC DataAnnotations and the RegularExpressionAttribute

A fellow Regex Hero user emailed me this morning about an inconsistency between what they were seeing in Regex Hero vs what they were seeing with the RegularExpression DataAnnotation in ASP.NET MVC . As a test, they were trying the following regular expression... ^A|B|C$ Against this string... ABC In Regex Hero you see 3 matches (as you should).  But in ASP.NET MVC it doesn't match, and validation fails. Why is this? As it turns out, the RegularExpressionAttribute is hiding an implementation detail.  In fact, I couldn't even find any mention of this on MSDN. It's most plainly visible if you open up the Javascript file that comes with an MVC project template, MicrosoftMvcValidation.js.  Inside you'll find this bit of code... var $0=new RegExp(this.$0); var $1=$0.exec(value); return (!Sys.Mvc._ValidationUtil.$0($ 1) &&  $1[0].length===value.length ); I've highlighted the important piece. It's checking to make sure the text value&#