REGEXHERO.NET

Thursday, October 6, 2011

Asynchronous Regex Matching and Highlighting

I came across a question on StackOverflow the other day where someone was trying to find the culprit for an unusually slow running regular expression. In fact it'd take around 30 seconds to execute. This was a rather extreme case of catastrophic backtracking. With just a few minor tweaks someone was able to drastically improve the performance, making it about 48,000 times faster. Yeah, pretty drastic and it really illustrates the importance of running a simple benchmark to test any regular expression that'll see heavy use.

It's rare that someone will write such a poor performing regular expression, especially by accident. But nevertheless, this circumstance is one where Regex Hero failed miserably. The trouble is that the regular expression was evaluated synchronously as you type. So if you're dealing with a slow running regular expression, this would actually hang the UI temporarily until it's finished. It was an ugly thing. But no more. As of today, Regex Hero now evaluates the regular expression on a separate thread, returns the results, and then highlights the matches. This asynchronous approach is much more user friendly as the UI is always responsive. In addition to this, by running the regular expression on a separate thread from the UI, Regex Hero is able to take better advantage of multi-core processors, actually improving the overall performance of the application. These are all good things. I hope you enjoy it.

Tuesday, August 16, 2011

Alternating highlighting, new string copy options, and more


Alternating Highlighting
I got some great feedback recently. First, magneticmail on GetSatisfaction suggested that I create two colors for Regex Hero's highlighting: an odd color and an even color. This had crossed my mind before but I hadn't really given it much thought. My initial concern is that introducing a new color could cause some confusion. What does the color mean? But after thinking about it, implementing it, and playing with it myself, I think it's simple enough. Once you actually write an expression that has 3 or more matches, it becomes obvious that the two colors simply alternate to provide some visual distinction. And the value that the visual distinction brings with it outweighs any potential confusion, I believe. So, thank you magneticmail for the suggestion. It's a simple change, but hopefully a change for the better. Let me know what you guys think in the comments.


Move to target string and start a new expression
This idea came from the author of RegexRenamer. The idea is to improve the workflow slightly when using the replace functionality to make incremental changes to a block of text. So you perform your replace operation, click the "Final String" heading, and then click "Move to target string and start a new expression". This will do just what it says, moving the final string to the target string, and clearing out the regular expression and replacement strings so you can start your next replacement operation.


Copy as a C# String or Copy as a VB.NET String
The .NET code generation feature has always created C# or VB.NET friendly code snippets, with properly escaped strings. Now you can actually grab properly escaped C# or VB.NET strings from any of the 4 subheadings: Regular Expression, Replacement String, Target String, or Final String.

Tuesday, August 9, 2011

Skype Screen Sharing with Steve

I've had good Regex Hero feedback slowly trickle in through GetSatisfaction, email, and a few phone calls over the past couple years. It's great to hear from you guys as I've been made aware of problems that I never knew I had.

And so in the spirit of improving Regex Hero, I want to try something new. I'm inviting all Regex Hero fans to contact me via Skype for a 30 minute one-on-one screen sharing session. This will be an opportunity for me to learn about problems you're having with Regex Hero and help out any way I can. Perhaps you're having trouble figuring out how to do something very specific in Regex Hero. It could be that a feature is missing, or simply isn't as obvious as it should be. Or perhaps you're having trouble with a regular expression and just need a little help. In either case, you'll share your screen with Regex Hero open as we dive into it. Email me if you're interested and we'll set up a time.

What you'll need...

Sunday, June 12, 2011

Bug fixes around undo/redo and copy/paste

I found a report of a case recently where Regex Hero would sporadically cause Chrome to crash. It was in a comment on StackOverflow, and I'm lucky to have found it. I didn't have much to go on, but I take reports like this seriously.

First of all, I had never seen this actually happen before. But I began by banging on things trying to make anything and everything break that I possibly could. My method is perhaps a bit crude and it simply takes time and some knowledge of what's going on in the code to get anywhere.

Here's what I managed to fix, in order of discovery:
  1. There was a layout problem involving the minimum vertical height of Regex Hero. After you shrink the window beyond a certain point a scroll bar appears so as not to fold the UI on top of itself. Well there was a logic problem in this calculation which could actually throw an error in certain circumstances. The error was being trapped though, and couldn't have caused the crash.
  2. The expand/collapse options button along the right hand side of the app had an unusual bug where, after clicking, the tooltip would be reused for other UI elements. I fixed it by using just one button rather than hiding/showing two different ones. Again, this was a weird bug but not one that could've caused the crash.
  3. Whenever you right click text and choose Cut/Copy/Paste, Regex Hero accesses the clipboard programmatically. On first use, this will throw a security warning from Silverlight (there's no way around that). The trouble is that if you choose not to allow Regex Hero access to the clipboard, Regex Hero would kind of fall on its face and not handle that condition gracefully. Again, an exception would be thrown, but it was caught and couldn't have caused anything to crash. I improved this process a bit and I now provide a follow up dialog.
  4. I took a couple days and came back to this. And just yesterday I finally reproduced the problem. The problem, it turns out, comes from another bug in the RichTextBox. And it's not isolated to Chrome. The same behavior occurs in IE9. Regex Hero was programmatically replacing line feeds with carriage returns when loading your previously stored text from isolated storage. I do this to ensure consistent behavior within the app. A separate string variable assigned to the text value of each textbox is then reshaped as necessary depending on if you have the CrLf option checked within Regex Hero. However, if you have more than 10 lines of text, then cut the top 9, then hit undo, the built-in undo functionality fails. The RichTextBox undo system seems to have a serious problem with carriage returns. It can't seem to fully restore from its history, only actually rendering 3 lines of text. The rendering pipeline then seems to be out of sync with what the text value actually equals. It's odd. And it causes Silverlight to freeze, sometimes bringing the whole browser down. I'm reporting this to Microsoft. My solution is to now replace all carriage returns with line feeds instead. Behind the scenes we have the same effect and the app works as it should, but it effectively avoids this bug.

Saturday, April 30, 2011

Bug fixes concerning tabs and syntax highlighting

The tab spacing bug

This problem stems from a bug in the RichTextBox. Basically, the tab spacing in the RichTextBox is inconsistent and very strange. Sometimes a tab will be bigger than a space, and sometimes it'll be smaller than a space. I have informed Microsoft of the bug and I'm hoping they'll fix it for Silverlight 5.

What this means for Regex Hero is that tabs would throw the highlighting out of alignment. So my fix was to override tabs with spaces. I had made this change weeks ago. But today's release has this same treatment on pasting tabbed text.

This isn't ideal and basically means the \t regular expression will never match anything in Regex Hero. If I can find a better workaround I will do it. But at least today's fix means that the yellow highlighting will always be in alignment and is reliable again.

To help ensure Microsoft fixes this bug in the RichTextBox in a timely manner, you can help by up-voting the bug here on MS Connect.

Syntax highlighting

The syntax highlighter had a minor bug with back slashes. The following regular expressions are valid, but the syntax highlighter was painting them red...

(abc\\)
[abc\\]

It was seeing the \ before the ending parenthesis, escaping the parenthesis, and then thinking that these constructs were not closed. It didn't look far enough back to see the \\. So I fixed the bug, and now it works properly.

Saturday, March 5, 2011

Syntax Highlighting

Syntax Highlighting
This feature was requested back in 2009. I didn't do it back then because I wasn't sure how I was going to do everything I wanted with it. Ever since the beginning I've always said that if I can't implement a feature right, then I wouldn't bother with it.

But I've learned since then and this week I gave it a try.  It took a little experimenting to find the right approach, but I'm pleased with the end result.

The syntax highlighter is built off of my existing parsing engine. In addition to highlighting basic constructs, it'll also detect unclosed parenthesis or brackets and paint them red. So for example (abc(def) would all be red.  I think this makes it easier to find mistakes. And I hope you enjoy it.

In addition to this I've fixed a few bugs and made a few improvements:
  1. I improved code completion when working with a multi-line regular expression. The down arrow key now responds more like you'd expect a good code completion system would.
  2. I optimized some initialization code and sped up the app slightly.
  3. I was able to remove an unneeded assembly.  The app is now about 40KB smaller. 

Thursday, February 17, 2011

Which Trial Experience Do You Prefer?

I've tried a couple different variations of trials over the past couple years.  But I've never asked you guys which you prefer.

Which Regex Hero trial experience do you prefer?