ActionScript Regular Expressions Testing Tool
This is a simple tool for testing regular expression patterns for ActionScript. I’ve found that whenever I’m working with regular expressions in any language, the hardest part is getting the intricacies of the pattern worked out. This becomes much more complicated when you’re trying to debug a pattern in the context of its containing application. I made the ActionScript Regular Expressions Testing Tool tool to help simplify the process of figuring out the right regular expression pattern.
The tool has two text input fields, where you enter the RegExp pattern you want to use (without the / / delimiters or option flags), and another where you enter a test expression. There is also a field for entering any of the optional flags you might want to use. Finally, you can choose whether to use the RegExp.exec() method or the String.match() method for testing capturing groups, because those methods behave differently with certain option flags set.
When you run a test, you get three sets of output:
- A boolean “match” field tells you if the pattern matches at all
- A “matches” section lists the index and value of all the pattern groups in the result array
- A “named matches” section lists any named match groups that were captured
Here is a link to a running version of the ActionScript Regular Expressions Testing Tool. From that page, to or download the source code right-click on the tool and choose “View Source”.
The source code for this tool is released under the Mozilla Public License, version 1.1.
If you have comments or improvements for the project, feel free to add a note in the comments or contact me.
You can leave a comment, or trackback from your own site.
6 Comments so far
Add your comment
Comment notes
Please keep comments on topic. Comments that are inappropriate or offensive will be edited or removed.
Paragraphs and line breaks are automatically converted to HTML, and quotation marks are converted to “smart” quotes.
The following XHTML tags can be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . All others will be removed.
July 29th, 2008 at 12:58 pm
Alex is reported to have said:
Hey there,
I had a question about something I’m working on. I’m a beginner at regular expressions and they confused the hell out of me. If anyone actually knows how to do this stuff could you give me examples of code and/or explain to me in very simple terms what I have to do?
What I’ve done so far is gotten the source of a page to come back to me in the form of a string. In this source there’s a table (in html), which I sort of need to use to create a table of my own… I mean, with those numbers in that table. So I used a regular expression to take out everything between the two tags. I basically used this to do that : var pattern:RegExp = /(.*?)/;
But now, I’m trying to create a 2-d array and put the columns and rows from the html table into that. So does anyone know how I can do that? What code to use?
Thanks!
July 31st, 2008 at 2:31 am
Matt is reported to have said:
Hi Paul
Thanks for your reg ex checker. It saves me countless headaches. I use it every time I need one. Great work.
October 16th, 2008 at 7:01 am
John Grindall is reported to have said:
Hi, neat tool!
I have a question about these RegExps. I’m trying to match a.*b in the string aab. I’m expecting two matches, ‘aab’ and also the final ‘ab’, but I only get one match, aab. I have the global flag set.
Any ideas?? Thanks!
October 16th, 2008 at 10:29 am
Paul is reported to have said:
@John:
There are a couple of reasons why you aren’t getting the result you expect:
1. Regular expressions process strings one character at a time. Once a character has been included as part of a match, it can’t be part of a subsequent match in the same pattern.
2. Regular expressions use “greedy” matching by default. That means that a single part of a pattern will include as many characters as it can. So “.*” in your pattern is going to include as many characters as it can, as long as they’re followed by a “b”.
3. The global flag makes it so that you can get more than one result from a string; however, the captured results must be completely separate (a single character can’t be included in multiple matches — per rule #1)
4. There is a way to “override” rule 1 and allow characters to match more than one part of a pattern. To do this you use a “positive lookahead group”. Unfortunately, positive lookahead groups are also considered “noncapturing groups” — so you can’t “capture” matches. In your example the syntax using a positive lookahead group would be “(?=a.*b)” — notice that the original pattern is surrounded by “(?=” and “)”. Even though we can’t see it, I believe that it does technically match twice. My reasoning is because if you run a test with the pattern “((?=a.*b))” and the string “aab”, using RegExp.exec() you get two indexed matches. (In that example, the positive lookahead group is surrounded by a capturing group.) Unfortunately the matches are empty — I guess noncapturing groups’ content isn’t included in a surrounding capturing group.
October 18th, 2008 at 9:19 pm
Ryan Swanson is reported to have said:
Hi Paul,
I just came across your site and found your regular expression tool. I recently created a similar tool and thought you might be interested in it. Especially since you have built a similar tool and likely thought through some of the similar ideas, I would love to get some feedback from you on what I have created.
The app is called the Flex 3 Regular Expression Explorer and can be found at my blog below.
http://blog.ryanswanson.com/2008/10/introducing-flex-3-regular-expression.html
The application is similar to the Flex Component and Style Explorers created by Adobe, but I have also added a collaborative community section where people can post their own regular expression examples as well as a full-feature help panel to get novices started with the technology.
Hope you like it!
Cheers,
Ryan
November 27th, 2008 at 2:13 am
ActionScript regular expression testing tool | monline is reported to have said: