Regular Expressions in Central

One of my favorite parts of the Central API is the RegExp object. Here some examples from an application I’m working on right now.

The “regular_expression.as” file:


var validUrlRE = new RegExp("^(http|https|ftp|file)://.+");
var titleRE = new RegExp("<title>(.*?)</title>");
var allAlphaNumericRE = new RegExp("^\\w+$");

Excerpts from the file that uses some of the regular expressions:


#include "util/regular_expressions.as"

if (validUrlRE.test(this.urlInput.getValue()))
{
// urlInput contains a mostly valid URL.
}

if (allAlphaNumericRE.test(this.nameInput.getValue()))
{
// this.nameInput contains alpha numeric characters
}

var title = titleRE.match(htmlSource);
trace(title[1]); // This contains the HTML file's title.

7 Responses to Regular Expressions in Central

  1. mesh on mx says:

    Regular Expression Library

    Digital Media Minute just posted a link to the Regular Expression Library which is a repository of Regular Expression expressions (currently with over 450 entries). This is a useful resource if your are developing applications for Central, as Central h…

  2. scott janousek says:

    Where can I find “regular_expression.as”?Can I use this outside of central?, or is only an API for central use?I want to do regular expressions in MX 2004, but my app is not central based.-sj

  3. Brian says:

    This code is very interesting

  4. Handbags

    I’m interested in blogging but I spend so much darn time on my designer handbags site. Come to http://www.couture-handbags.com/ if you want a deal though gals on handbags.

  5. Handbags

    I’m interested in blogging but I spend so much darn time on my designer handbags site. Come to http://www.couture-handbags.com/ if you want a deal though gals on handbags.