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 “” 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/"

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.