Skip to main content

Posts

Showing posts from 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...

Improved TextBoxes With Better Whitespace Support

Today's update is all about whitespace. I've created a new textbox control for Regex Hero which is now being used for the 4 main textboxes: Regular Expression, Replacement String, Target String, and Final String. The new features are as follows: Figure 1: Matching Line Feeds Handles tab characters as it should. You can test this by entering \t in your regular expression and then hitting tab in your target string. Matching carriage returns or line feeds are now visible with a half-width character block (as seen in the figure 1). You may preserve the formatting of pasted text with the new "Preserve pasted formatting" option.  This will retain the existing line endings of your source text as was suggested about a month ago. Cycling through your matches with the up & down buttons is now much more responsive.

Now Supporting Facebook and Twitter Logins

This is something I've wanted to have for a long time but I simply haven't set aside the time to do it. Well, no more waiting, Regex Hero now supports logging in with Facebook and Twitter... If you already have an account with Regex Hero and want to sign in with something else (such as Facebook or Twitter) then you can add it to your account .  Or if you're a brand new user of Regex Hero, create your account here .

New Benchmarking Features and a New Homepage Design

Today I updated the benchmarking tool in Regex Hero with some new functionality. There were essentially two things I was looking to accomplish: Create insight into the benchmarking tool so that developers know exactly what it's doing. Add the ability to benchmark your regular expression with the IsMatch() function.  IsMatch() simply returns true if your regular expression has even 1 match in the specified string.  As such, it actually stops searching after the first match is found.  In some cases this makes it many times faster than iterating through every match. So now you'll see some new options to take care of all this... You can click the Show/Hide benchmarking code button at any point if you want to know exactly what Regex Hero is going to do under every benchmarking loop.  There are effectively 4 different benchmarking modes: 2 modes when the Match tab is selected, 1 mode for Replace, and 1 mode for Split. Homepage Redesign And of course I...

Highlighting for Regex Group Pairings

I added a new feature where the respective group starting and ending will be highlighted in gray when the cursor is on either the start or end of the group.  This is especially useful when you have a large regular expression with many groups, or perhaps nested groups as below... The idea for this comes right from Visual Studio 2010 which of course I use everyday.  And this feature is very responsive because of the fact that Regex Hero doesn't have to reparse anything when you're simply moving the cursor around.  Once again, the new parser is doing its job very well.

Improved Regex Code Completion and Bug Fixes

I've taken another step towards leveraging the new regex parser this weekend.  This time I've completely removed all dependencies on the old parser for the purposes of regex code completion.  So the syntax highlighter and code completion features are both running on the new parser.  This saves precious clock cycles and makes Regex Hero a little more efficient.  And then I've introduced full support for Unicode general categories and named blocks denoted by the \p{name} or \P{name} syntax.  So you'll get regex code completion for this as well. In addition to this I've solved a few bugs: The analyzer would get out of sync under certain situations, causing the list to be tabbed over needlessly. Code completion would have issues when you try to navigate down the list and then back past the top result with the arrow keys.  Hitting down again wouldn't return focus to the list as it should.  I actually changed this behavior so the list will disappear ...

New Regex Parser, Improved Syntax Highlighter, and More on the Way

During the past couple weeks I've been working on a revised version of my regex parser.  For those who haven't followed my old posts about this parser, it's what makes some of the more advanced features in Regex Hero possible.  It's being used for code completion, regex analysis, and the syntax highlighter. Well, my new & improved parser is both faster and more powerful.  Today I released an update which uses the new parser for the syntax highlighter.  It's roughly twice as fast as the old parser.  And the syntax highlighting is a little smarter now about detecting unclosed brackets or parentheses, and highlighting the offending section in red.  It'll also highlight invalid character constructs such as \g in red. But this is just the tip of the iceberg.  There are a lot of improvements coming that'll be made possible by this new parser.  Stay tuned for updates.

Faster Load Times for Regex Hero

I took a lesson from my own blog post yesterday about lazy loading and made some drastic improvements to the load time of Regex Hero today. Essentially I'm now loading things like the analyzer and benchmark tool only when they're first called. This reduces the amount of work that has to be done when Regex Hero is first launched. And it should even reduce memory consumption a little bit if you're not using these features. The end result is that Regex Hero loads about half a second faster than before. This affects both the web version and the desktop version. Enjoy.

A Quick Tip About Using RegexOptions.Compiled

Since Silverlight doesn't support RegexOptions.Compiled, it's the one option that's missing from Regex Hero . In a full .NET application there may be times when it's worth it to use this option.  It adds significant cost to initializing the Regex instance, but it can also double the speed of the regular expression itself in some cases.  Therefore it's best to use when you can instantiate the Regex object once, and reuse it many times.  Jeff Atwood talks about this very point in his article, To Compile or Not to Compile . So if you've determined in your case that RegexOptions.Compiled is worth the initial cost of compilation, then I'm going to offer one simple solution that we as programmers often forget about. Lazy Loading The advantage with lazy loading is that the object we're concerned about is only instantiated when it's first accessed.  Therefore, we can use RegexOptions.Compiled without necessarily hurting the initial start-up time of ou...

Faster Regex Syntax Highlighter

After the recent performance improvements to the analyzer I found that the next bottleneck was the regex syntax highlighter. You know, that's what paints your regular expression pretty colors. The slowness has probably affected fewer than 1% of the Regex Hero population. I say that because it was only really perceivable when dealing with a regular expression over 2,000 characters long. Nevertheless, I had an idea for how I can improve it. The slowness had nothing to do with parsing speed, and everything to do with how I was drawing the characters. I was dynamically adding characters in colored sections to a single text block to create the colored effect. This, as it turns out, is not optimal. So what I did is I created text blocks on top of eachother (one for each color), and then simply assign the appropriate text values to each one. For example, the text blocks might be composed of... test     (     )       \d\w     ...

Faster Regex Analysis

Today I got rid of the tree view in the analyzer in favor of a staggered listbox. It was kind of cool to be able to expand or collapse individual items in the tree view, but it came at a cost.  The tree view is extremely slow when you're constantly updating it.  And of course, since everything in Regex Hero is supposed to happen in real-time, the tree view had to go. With today's changes the analyzer feature is now at least 5 times faster.  And with the staggered listbox we can still easily visualize the nested nature of a regular expression, as you can see in the example below...

Optimizing Your Regular Expressions

Regular expressions will backtrack.  That's an unfortunate thing about them because backtracking can be slow.    And in certain (rare) cases the performance can become so awful that executing the regular expression against a relatively short string could take over a minute.  There's a good article about catastrophic backtracking over at regular-expressions.info . And today I created a video about all of this called  Regex Lesson 5: Optimization .  In the video I start with a very poorly written regular expression and make several improvements to it, using the benchmarking feature along the way.  By the end of the video I make the regular expression over 3 million times faster. In addition, today's update to Regex Hero provides a little message in the event that you encounter a regular expression that takes over 10 seconds to evaluate... And then last of all, I changed the benchmarking feature a bit.  In the past it would simply test your...

Benchmarking Bug Fix

Today's update is a small one.  I discovered that under certain situations the benchmarking feature in Regex Hero would fail and return NaN values.  I solved this problem today so we shouldn't be seeing that again. I also made a couple recent changes to the site for better performance.  For one, I switched from the Rackspace CDN I was using back to Amazon CloudFront.  Amazon's CDN isn't necessarily the fastest in all countries, but it's very reliable and consistent.  Then I extended the cache/expiration settings for the site's CSS file and the loading screen for Regex Hero so repeat visitors should enjoy improved responsiveness.