Skip to main content

Posts

Showing posts from 2010

When to use and when not to use Regular Expressions

Regular expressions are powerful.  There's no doubt about it.  The .NET and Perl-derived implementations in particular are rich and capable. For the most part regular expressions are there to save you time from parsing text the hard way.  But if you're spending more time bending regular expressions to your will to accomplish something that could be done more easily and efficiently with procedural code, then that kind of defeats the purpose. I've wanted to write this article for awhile.  Then today I stumbled across this StackOverflow question  which is a prime example where the procedural solution was actually quicker & easier to write, more understandable, and more efficient.  Your ability to identify these situations will improve naturally with experience.  But I thought I'd list a few good & bad scenarios for regular expressions... Good Data validation can be done easily and concisely with regular expressions in most cases. Good ...

Regex Analyzer

Regex Analyzer Regular expressions are one of those things that many programmers dabble with enough to understand the concept, but not enough to memorize the syntax. Code completion is a big step towards making things easier. Beyond that, sometimes an explanation written out in English is just what you need. The new "Regex Analyzer" feature actually uses my existing parsing engine that I used for code completion to step through the regular expression and build a tree which explains, in English, every construct.  When you click a line in the explanation box, it'll highlight the corresponding section of the regular expression. This feature is only available in  Regex Hero Professional . By the way, in addition to this feature, there have been a few more improvements in today's release... Added a new menu with icons underneath the existing file menu for easy one-click access to common features. Moved the spot where the open & save dialogs and all of t...

Greatly Improved Benchmarking

The benchmarking feature has always had a couple of shortcomings. It covered up the lower-half of the application as you used it. You couldn't easily revert back to the best performing regular expression.  Or you had to rely on your memory to know what performed best. Well I think I managed to come up with a pretty good solution for both problems.  First, you'll notice that the benchmarking feature now sits in its own panel below the rest of the UI.  If your screen resolution isn't high enough there will be a vertical scroll bar so you can still scroll to see everything. And then to solve the second problem I knew I needed to make some bigger changes.  I realized that a configurable number of iterations was adding unnecessary complexity.  Instead I simply run the benchmark for one second.  And now we can rely solely on the iterations per second figure.  And then I decided to go the bar graph route.  Each time you hit "Start" to run a benchmark...

A couple bug fixes and a new video

Yesterday I found a couple bugs. Tabbing or untabbing multiple lines of text would occasionally fail. The size of the tab itself was inconsistent inside the textbox. This seems to be a glitch in the RichTextBox itself. I solved both bugs yesterday and it's working fine now. Then today I created a little promotional video for Regex Hero Professional . It's definitely of a different style than the other videos I've made. It's a little light on dialog and a little heavy on demonstration. Also I've included a couple clips from royalty-free songs I purchased from SoundSnap.com today. Let me know what you think.

Regex Hero Now Handles Wide Spans of Text

There's been a bug in Regex Hero (and in Silverlight) ever since it launched. It's something I've tried to fix on many occasions but was always left in tears. The problem lies with scrollable textboxes. You see, Regex Hero doesn't word wrap. If it did, the instant highlighting would be much, much slower. So if you're pasting a huge block of text that is over 25,000 pixels wide into the textbox, of course you'll be doing a lot of scrolling. The bug was a strange one. After a certain limit the text would essentially go blank as you're scrolling. This was incredibly annoying. Finally, Microsoft released the RichTextBox control in Silverlight 4. It's a much more powerful control, and best of all, it doesn't have this bug! I've spent the last 3 weeks implementing changes to make the RichTextBox work within Regex Hero... In making this change I've also solved a problem with my multiple undo/redo system. That's simply because ...

New Version of Regex Hero Leverages Silverlight 4

Yes, I have finally taken the plunge. My stats show the adoption rate for Silverlight 4 has reached 78%, which is pretty close to my target. The immediate improvements you'll notice are right-click context menus for the textboxes... As well as support for mouse wheel scrolling. These are both small, simple, but much needed features. I'm still working on improving real-time highlighting. And I'm still on my quest to figure out word wrapping. Meanwhile, I also have some ideas on how I can further improve the benchmarking feature. Look for another release coming next week.

Silverlight 4 Adoption Rate at 75%, Regex Hero Update in the Works

I blogged awhile back about the Silverlight 4 adoption rate on the Regex Hero site . Naturally the figures on the site are a little higher than the worldwide averages. But at this point Silverlight 4 has overtaken Silverlight 3 by a healthy margin. In fact Silverlight 4 is at a 75% overall adoption rate as collected by my Google Analytics profile this past week... My plan was to launch a new version of Regex Hero after Silverlight 4 surpasses the 80% mark. And things are looking good. In my own testing with Silverlight 4 the instant improvement was the function of the mouse wheel. I didn't have to change a thing to make this happen. After I set Regex Hero to target Silverlight 4 all the textboxes were scrollable with the mouse wheel. I'm also working on the right-click context menus for cut/copy/paste, and undo/redo. If all goes well I'll release a new version next week with these improvements. Meanwhile I'm also working on incorporating the more powerful...

New 7-Day Trial

I've been lacking a good way for you guys to try Regex Hero Pro before you buy, until now. The new trial lasts 7 days and allows you to experience everything Regex Hero Pro has to offer, including code hinting. To start the trial all you have to do is create a login . Or if you already have a login, then the trial will automatically start the next time you visit Regex Hero .

Code Hinting for Replacement Groups

I was planning this one for awhile. I just needed to set aside some hours to build it. Code hinting has been available for regular expressions for a couple months. But now all pro users will see code hinting for the replace box as well... You can see the named groups ${LastName} and ${FirstName} at the top of the list. My hope is that this will promote the use of named groups in regular expressions, rather than numbered groups. I think named groups have a way of better expressing the intention of the regular expression and to be able to select them from a list is pretty awesome. Enjoy.

Selection Bug Fix when CrLf is Checked

I discovered yesterday that in some cases the wrong text is selected when you're stepping through the matches with the Previous/Next buttons. Specifically it would happen when you're working with multiple lines of text and "CrLf marks a line ending" is checked. I just now fixed the problem so it won't happen again.

CPU, Memory, and Hard Drive Usage Improvements

I made a few improvements to the application this weekend. I managed to find a more efficient way of doing a few things, eliminating unneeded steps during each regex matching cycle for real-time highlighting. In so doing I've sped it up slightly. I also found that I was calling the auto-save function a little too frequently so I tweaked the interval settings. That should reduce memory and hard drive usage when working with large target strings. And lastly I turned on GPU bitmap caching for several elements within the app. GPU acceleration features in Silverlight are still minimal, but this is one thing I'm able to do that actually has some small performance benefits.

New "Regex Hero Pro" Name, and a Lower Price

When I released "Regex Hero for Desktop" several months ago I had named it the way I did because I was inspired by Balsamiq Mockups for Desktop . In fact Regex Hero shares a lot in common with Balsamiq the way we both started. I mean, obviously their app is a prototyping tool and mine is a regex tool. But Regex Hero is supported and maintained by just one man (me), as was Balsamiq back in the day. And they have a killer web app that thousands of people use, as do I. ;) However, I've come to realize that while I do admire Balsamiq and just about everything they do, my app is just not the same. You see, Regex Hero is actually very usable on the web. And when you buy it, you get an account and license key which then allows you to use all of the features all within the web version. You can then optionally install the desktop version and get all of those same features. So because the paid version can be run with the same feature sets inside or outside of the brow...

Silverlight 4 Adoption Rate Approaching 25%

A week before Silverlight 4 came out I added some Javascript to the tester page to track what version of Silverlight everyone was running and feed it into Google Analytics. Silverlight 4 is still very new of course but I think it is interesting how many Regex Hero users have already upgraded. The adoption rate here is much higher than the stats from riastats.com would suggest (which of course spans a large variety of sites). Here's a screenshot from Google Analytics showing the breakdown of Silverlight versions on regexhero.net/tester/ during the past 2 weeks: "Silverlight 0" was my way of saying Silverlight is not installed. Regex Hero is still built on Silverlight 3. But I'm going to begin working on some major improvements to Regex Hero in the upcoming weeks. Silverlight 4 is going to allow me to add some awesome features that I'm looking forward to. And my plan at the moment is to launch the new Silverlight 4 version when the adoption rate surpa...

New Video Lessons

I began a new series of video lessons explaining the basics of regular expressions. I'm trying to be thorough in each lesson without talking about concepts that'll be learned in later lessons (a more difficult task than I expected). I have 3 so far, and I'll add to this list as I go: Introduction to Regular Expressions Regex Lesson 1: Characters Regex Lesson 2: Quantifiers Regex Lesson 3: Assertions

More Code Hinting Bug Fixes

I discovered a couple of bugs with the code hinting this week. In some cases when you have constructs with a slash such as \d and \w at the beginning and end of an expression, then the code hinting for the parenthesis wouldn't work properly in the middle of the expression. If you type out the first few characters of an expression and then select it from the code hinting list, it wouldn't always put the caret in the right spot. Again this was most often seen when typing in the middle of the expression. I'm glad to say that both of these issues are now fixed.

Improvements to the Library

Ah yes, the library. The library only has 13 regular expressions in it at the moment. So I've been working on making it more compelling to contribute. A couple weeks ago I added a tagging system and incorporated a faceted search engine for the library visible from the website. Only I have control over the tags for now as I'm still building out all of the interfaces. But this is one way to filter the regular expressions that I'll be relying on heavily as the list grows. Then just this weekend I refined the list inside the tester itself (soon I'll add tags and sorting to this as well): And I built out a voting mechanism: The voting mechanism will only appear for regular expressions out of the public library that are not your own. And it'll slide away after you vote. This should make it much more convenient to vote, and hopefully more compelling for developers to contribute as a result. Coming up next I'll have a points and badges system in pl...

Stopwatch Threshold Logging

Today's post is not related to regular expressions at all. In fact it's not really related to Regex Hero except that it potentially affects the website. But I figure I'd write about it here anyway. I've been diagnosing some intermittent web server performance issues for awhile now. And in effort to gain some insight into which pages are slow and how often, I wrote a simple logger. The idea is to time the ASP.NET page lifecycle from start to finish, and if it exceeds a certain threshold, then log it. The advantage of this approach is that it's not going to waste processing time logging the stuff I don't care about. If you're interesting in this for yourself and you're running ASP.NET all you'd have to do is add the following to your global.asax: private Stopwatch sw; protected void Application_BeginRequest() { sw = new Stopwatch(); sw.Start(); } protected void Application_EndRequest() { sw.Stop(); if (sw.ElapsedMilliseconds ...

Bugs fixed, Improved Efficiency, UI Tweaked, and Code Hinting Improved

Bug fixes When you press the down arrow key the focus shifts to the code hinting box, but holding down the key wouldn't do anything unless you lift and press again. Now as you press and hold the down arrow key, the selection will rapidly move down the list. The code hinting box wouldn't go away when you shift focus to the target string or click in the regular expression box. Now it will. The app would throw unfriendly errors if you have disabled Isolated Storage. Now it won't. The app would throw unfriendly errors occasionally when trying to step to a match that doesn't exist. Now it won't. Improved Efficiency I've enabled output caching on the home page as well as the tester to improve ASP.NET performance, if only slightly. I've combined three separate web service calls upon initialization to only one. This will reduce the time it takes for the tester to recognize your login. UI Tweaks I've changed the placement of the code hinting popup to...

Silverlight 4 release date confirmed: April 15th, 2010

What I had suspected is now confirmed. Silverlight 4 will be launched along with Visual Studio 2010 on April 12th. If you're in the Las Vegas area you can even register for the launch event . Or you can watch it online . I've talked before about how Silverlight 4 will affect Regex Hero . So needless to say, I can hardly wait for it to 1.) be released and 2.) reach a large enough audience for me to make the switch. I'm going to be keeping an eye on riastats.com for adoption rates. UPDATE: So the official Silverlight 4 launch was broadcast live today. And I learned that in fact the actual release date will be April 15th (Thursday). UPDATE #2: Silverlight 4 is live! Get it here: http://www.microsoft.com/getsilverlight/get-started/install/

Major UI Overhaul

I was pretty proud of Regex Hero's simplicity in the beginning. But I've built Regex Hero little pieces at a time for the past year. As such, I've gone in a few different design directions and the usability has suffered a little. I'm a programmer 1st, designer 4th. That's no excuse, really. If I was a more disciplined designer I wouldn't have let this happen. But nothing in Silverlight development is final. So I sat down this weekend to solve some of these UI problems, and solve them well. My Inspiration Bill Buxton has talked about creating a common design language for an application. What he's getting at it is that the design of your application should be consistent throughout so that when you explore a new section of the application you'll instinctively know how things work. For instance, new dialog boxes, windows, and basic UI elements should always appear in a consistent, and therefore, predictable manner. Likewise, the color scheme o...

Introducing Code Hinting for Regular Expressions

It's been a long time in the making but code hinting is here, and I'm pretty excited about it. I've created a short code hinting demo that shows it off a bit. This feature is available only to licensed users . If you're a licensed user and you open up the tester now you'll see hints appear as you start typing an open parenthesis "(", bracket "[" or brace "{". I took a lot of inspiration from Intellisense. In particular, I based my design off of the Intellisense in Expression Blend. I like the look & feel of Expression Blend. But the regular expression language is so different than anything Intellisense is used for. So functionality-wise I was on my own. I knew one thing I didn't want. I didn't want the code hinting to aggressively autocomplete. In other words, Intellisense in Visual Studio will sometimes autocomplete whatever you're typing at the time, sometimes adding code that you don't even want...

Proper Off-Site Backups Have Been Configured

When the site was hosted with Orcs Web they would backup the server for me as a part of their managed hosting. Now that I'm with Liquid Web and I've opted not to use their $100/month Guardian backup service, backups are on me. So today I set up a database backup maintenance plan. Every night the server will create full backups for every database in SQL and save the backups to the extra (backup) hard drive in the server. I've got the backups configured to expire after 14 days. Essentially what this means is that I'll have quick restore capability for any day up to 2 weeks in the past. But that's really not enough. So in addition to this I've signed up for MozyPro off-site backup. I've used MozyHome on my home computer for the past year and I've been pleased with their service. The MozyPro service is slightly more expensive than MozyHome. But MozyHome will not run on a server, so MozyPro it is. I configured MozyPro to backup nightly just a...

Code Hinting for Regular Expressions : The Theory

I haven't heard much feedback on my code hinting post in January, perhaps because the first demo is not too impressive. And in fact I haven't been able to work on it as much as I wanted. But I'm still thinking about it and planning the user interface. There's still a lot to do to make this as well polished as Intellisense is in Visual Studio or Expression Blend. In fact I'm drawing more inspiration from the Expression Blend interface, but that's another story. When I first started on this I knew that I needed to parse the regular expression on the fly and display the hints based on the text next to the caret. I begun by researching parsing theory. Now, I know what you're thinking. Why bother? Why not just use regular expressions? Well, I knew that regular expressions are ill-suited to parse HTML , and I thought that they may not be the best choice for parsing themselves, either. The reason I thought this, it turns out, was completely valid. Reg...

Silverlight 4 Coming in April, or Maybe Sooner

The exact release date has not been announced. But Visual Studio 2010 RTM is coming out in April and I think it's safe to assume that Silverlight 4 will be released no later than that. Each release of Silverlight has brought massive improvements over the previous version. And once again, Silverlight 4 does not disappoint. There is a long list of improvements but the ones that I think that will affect Regex Hero are as follows: RichTextBox My plan is to use this in place of all 4 major textboxes in Regex Hero. The new RichTextBox has built-in multiple undos & redos, so I can ditch my home-brewed code. It should be nice to use for syntax highlighting for the regular expressions I intend to create. It also has a built-in API to determine the pixel position of the text. I should be able to use this API and build a new highlighting scheme based off of it. This should do a couple things. First, I should be able to finally fix the problem I had with the ScrollViewer and ...

C# Code Generation Bug Fix and Improved "Jump To" Functionality

There was a bug in the C# code generation involving improperly escaped quotes. I'm using the string literal syntax with the @ sign. And when you do that, quotes are no longer escaped with \". Instead, it works more like VB with double quotes "" where the first quote escapes the second. I overlooked this but a fellow user of Regex Hero pointed this out to me today (thanks Jason). And after a small code change it works properly now. Secondly, I made a small improvement to the universal match count / group count / stepper control in Regex Hero. The up/down buttons will normally select a match and scroll to it. But when there's only 1 match, then the up/down buttons are disabled. So in the event that there's only 1 match you can now click the text that says "1 match" and that will select and scroll to the match. It's a simple change but I think it helps.

Upgrade Complete : Behold the Speed

So the server migration is complete. I ran into a couple problems along the way that were all related to server configuration. But this new dedicated server seems pretty nice. And it should completely resolve the performance problems the site has been experiencing the past few weeks. While I was at it I also moved the blog to blog.regexhero.net so it can be hosted by Blogger. I did that because Blogger will soon be canceling their FTP service that I was using. Apparently there's only a small percentage of Blogger users who used that service. Anyway, making the switch does mean that I'm able to use some nice features I wasn't able to before. For example, you'll now see a list of categories in the right-hand navigation. It's such a simple thing but that's something I've wanted for a long time.

Upgrading to a Dedicated Server

The virtual dedicated server this site is on hasn't really been working out for me. The site can be sporadically and inexplicably slow at times. I mean, inexcusably slow. A virtual dedicated server is supposed to be designed for someone like me -- a control freak who doesn't want to break the bank. But when the other customers on the host machine are calculating the next largest prime number while simultaneously rendering Avatar 2, then no amount of virtual separation will eliminate those slowdowns. So for a little more than twice the price, I ordered a dedicated server from Liquid Web last night. And they finished setting it up this morning. The server has a dual-core AMD processor, 2GB RAM, two 250GB SATA hard drives w/ RAID 1, one 250GB SATA secondary drive, Windows Server 2008, and SQL Server 2008 Web Edition. It's in a facility with a ridiculous amount of network and power redundancy. So it should be good. This weekend I'll be migrating the sites over ...

Upgraded to Silverlight 3 and Created the Desktop Version

Silverlight 3 was a substantial upgrade over Silverlight 2. The biggest feature, by far, was the introduction of Silverlight's out-of-browser capabilities, essentially allowing you to install a Silverlight app on your desktop. A beauty part of this feature is that since it's still running in Silverlight, it'll work on both a PC and a Mac. Cross-platform development has never been so easy. This has allowed me to create a new version which can be installed on your desktop in two clicks. This desktop version is available only to licensed users. So if you've already bought Regex Hero you should now see a link on the right hand side of the screen: Click that and you'll get this dialog box: And then once you click OK, you're done. Shortcut icons will be placed appropriately. And the desktop version looks like this: If after installing you want to uninstall you can do so by right-clicking inside the application and simply clicking "Remove this ...

Sneak Peek: Code Hinting

In my opinion this is the coolest feature since Regex Hero first launched. Soon this will be making its way into the paid version. I still have some more work to do to perfect it. I want to make it a little more intelligent. And of course I need to provide tool tips for everything. Once that's done this should be a very helpful addition.

Improper Highlighting Bug Fixed

Apparently I introduced a bug with the last major update to Regex Hero. The multi-threading I put in place had a few problems. On rare occasions you'd see highlighting that made no sense at all. I'm doing multi-threaded auto-saving, multi-threaded benchmarking, and even multi-threaded initialization in Regex Hero. But I need to set aside more time to figure out a way to do multi-threading for the real-time highlighting more reliably. For now I had to revert back to the old way of doing things. It may not be fast when dealing with massive amounts of text. But at least it's reliable.

Account Recovery with OpenID

I made some improvements to the login system this weekend. The biggest improvement is the new ability to recover an account when you can't login through your primary OpenID provider. I asked a question on StackOverflow a couple months ago about how this should be implemented. This is something I've been meaning to do for awhile but on Friday there was a sense of urgency as there were some peculiar issues with MyOpenID.com occasionally preventing you from authenticating. So I made a video to explain OpenID as well as the new account recovery feature: I am pretty happy with the way things turned out at this point. I've been using OpenID logins on Regex Hero for several months now. The excellent DotNetOpenAuth project has simplified things from my end tremendously. And now that this account recovery feature is in place I can sleep a little easier.

New Videos Section, Improved Responsiveness, and Better Memory Efficiency

Videos After I created the new library section which allows voting and comments I now have some very useful pieces to build upon. So this weekend I created a new videos section to complement the library. To start off with I created a video to demonstrate the process of writing a Strong Password Regular Expression . I decided to host the videos myself and use a Silverlight video player . The player I used is open-source and very slick. I made a few modifications to it for my own use. I primarily worked on the media controls auto-hiding behavior and I think I finally have it the way I want it. Improved Responsiveness While that would ordinarily be a productive weekend, I've been meaning to make a couple technical improvements to the tester for some time now. The first issue is a general slowness when you're dealing with a huge target string with real-time highlighting on. The trouble is that the application has to run the regular expression, calculate the positions...

SQL Server Didn't Start This Morning

I apologize for the downtime this morning. ORCS Web took the virtual dedicated server down early this morning for some security patches. As usual they are really good about being proactive with server maintenance. And fortunately they typically choose a time when nobody's really using the site anyway. However, when the server came back up this morning the SQL Server instance didn't. So they are investigating why that is so it won't happen again. UPDATE: I just got word back from ORCS Web: "I changed the server to 'Automatic (Delayed Start)' which usually fixes this problem. SQL will sometimes not start if there are not enough resources available, delaying the start generally resolves that problem." So hopefully that'll fix it.

Improving the Library

I've been spending some time the past several days working on a new page of the site, the .NET Regex Library . I wanted to set the groundwork for this section of the site so that it may grow into something substantial. So I borrowed some ideas from StackOverflow by incorporating a rating system. And then I added the ability to add comments as well. At some point it's going to require a search engine, and for that I already have some ideas from another recent project. The idea then is that the order of the search results will be based of votes and relevance, hopefully making it much easier to find what you're looking for. The same search engine will make its way into the Regex Hero tester itself. Anyway, allow me to back up a bit. The regular expressions in the library were all created within Regex Hero. As such they have been tested with the .NET regex engine, which is kind of cool. On top of that, anyone can contribute to this library, which is very cool. You m...

Year in Review 2009

I spent most of my weekends in 2009 working on Regex Hero. I've enjoyed working on it more than any other project last year. Regex Hero also has the distinction of being the first product I've ever sold on my own. I gave away 105 licenses during a promotional giveaway, and then I sold one copy in December. As I promised, I gave the proceeds from December (all $14.11 of it) to the Alliance for Children Everywhere organization. They'll use it wherever it's needed most. And although it isn't much, I know every little bit helps. Of course I wish I had done better in December. But I think I know why I didn't. There still isn't enough incentive to buy Regex Hero. There are some very cool features I'm working on which should help. Some of these will only be available to licensed customers. I'm constantly trying to figure out which features should be free and which shouldn't. Those decisions can be tough. But as always, I'll blog ab...