Raymond Camden's Blog Rss

Update to my Apollo regex checker

2

Posted in | Posted on 03-21-2007 | 2,153 views

I love you guys so much that I spent my lunch not just watching the Young and the Restless, but also improving my ugly little Apollo Regex Checker. (Ok, so I did watch Y and R while I coded.)

This new version now uses HTML mark up to show your matches, and lets you toggle between one match and multiple matches.

I have to say I really went down the wrong path trying to get my regex working right. Turns out there was a much simpler way to mark up the matches. This is my new AS code:

view plain print about
1private function testRegex():void {
2    var regexStr:String = regex.text;
3    var bodyStr:String = body.text;
4    var options:String = "";
5    
6    if(regexStr == '' || bodyStr == '') {
7        mx.controls.Alert.show("Please enter a regex and a body.");
8        return;
9    }
10
11    if(global.selected) options = "g";
12        
13    var regexOb:RegExp = new RegExp(regexStr,options);
14
15    //any matches?
16    if(!regexOb.test(bodyStr)) return;
17
18    body.htmlText = bodyStr.replace(regexOb,"<b>$&</b>");
19    
20}

Next will be a version that lets you test replacements as well.

By the way - Apollo notices if you run the same AIR twice. It asks you if you want to replace the old version. Sweet.

Download attached file

Comments

[Add Comment] [Subscribe to Comments]

Raymond, this is neat and all, but how about some Paging in Flex on a datagrid? :-) Kidding, but seriously this is some great stuff! Keep it up
In my spare time... ;)