File Exchange Pick of the Week

Our best user submissions

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Regexp Builder 1

Posted by Guest Picker,

Idin's pick for this week is the regexpBuilder by Michael Ryan.

Regular expressions can be a powerful tool in searching through strings or documents. If you haven't used them before, think of them as a string pattern matching tool on steroids.

MATLAB introduced support for regular expressions in MATLAB 6.5 (R13). You can read about regular expressions in MATLAB here. There are also a couple of blog posts on Loren Shure's Art of MATLAB here and here.

Despite their usefulness, the drawback to regular expressions has always been their non-intuitive syntax. For example, how do you find all strings that start with a capital "B" and end with "e"? Here is one option:

regexp('Bobbie was born on Bastille Day before dawn.', 'B[a-z]*e')

Now what if I want to ignore case? Or allow spaces within the string? Regular expressions can handle all these cases, but it takes some experience, and some doing.

Michael's regexpBuilder is an app that allows the user to interactively build their regular expression and see the results in real time. It even has checkboxes for some of the more common tasks (e.g. "ignore case", or "match once"). This can help reduce the time (and frustration) needed to construct the desired regular expression.

The user interface is quite simple: enter the text-to-be-searched in the big "Text" box, then start entering a regular expression in the top left "Regexp" box. The tool displays the results by highlighting and/or underlining the matches in the text window, but it also goes further: it lists all the different outputs from MATLAB's regexp function on the right-hand side of the screen. And just to make things a little more convenient, when you press the "Evaluate" button, it also echoes the equivalent MATLAB command at the MATLAB command prompt.

Suggestions for improvements

This app accomplishes its advertised task quite well. Here are some ideas on what could be added:

  • The user interface could be cleaned up to look more professional
  • The text boxes on the right aren't supposed to be used by the user, and should probably be locked so the user doesn't type in them.
  • Ability to import text files and/or web page would be nice.

As always, your thoughts and comments here are greatly appreciated.


Get the MATLAB code

Published with MATLAB® R2013b

Note

Comments are closed.

1 CommentsOldest to Newest

Michael Ryan replied on : 1 of 1
Hi, Thanks a lot for picking regexpBuilder as pick of the week! I'm glad people find it useful. As far as the improvements go, I've incorporated file importing and locked the text boxes into the next version but I'd like some clarifications from the everyone on making it look more professional. I noticed that some of the alignments are off, and I've added icons to some buttons (instead of the V for instance), but what else would be helpful? Also, I don't know what other people use this for, but I've found it helpful with the Cody Challenges. Michael Ryan