Category Archives: RegExp

Checking if a character is whitespace using the Flex StringUtil class’s isWhitespace() method

The following example shows how you can check whether a character is a whitespace character by using the isWhitespace() method in the mx.utils.StringUtil class. And just for giggles, I also show how you can do the same thing using regular expressions (RegExp) with POSIX character classes.

Full code after the jump.

Continue reading Checking if a character is whitespace using the Flex StringUtil class’s isWhitespace() method

Validating data using Regular Expressions

It looks like I forgot to post this and I’ve had this as a draft for a week. I was looking at creating a regular expression for validating a UPS tracking number and/or InfoNotice number and decided to do a quick RegExp for validating a Canadian postal code instead. Fear not, my 3 loyal readers, I’ll post the other regular expressions later on.

Full code after the jump.

Continue reading Validating data using Regular Expressions

Using named groups with Regular Expressions

This is always a neat trick that I seem to always forget about, so I thought I’d post it here. When working with Regular Expressions, the RegExp class supports named groups. So instead of having to go through the RegExp result and access it like an array ([1], [2] .. [n]), you can use named results. Long story short, it can make working with the results a bit more intuitive. I made a simple example below which parses the user’s Flash Player version and displays the operating system/platform, major revision, minor revision, build number and internal build number.

Full code after the jump.

Continue reading Using named groups with Regular Expressions

Filtering an XMLListCollection using the filterFunction property and regular expressions

Here is another handy little tip that you see all over the web, how do I filter a data grid (or other list-based control) based on a user’s input? Or more specificially, how to I limit the items that show in a list based on what a user types.

Since I already created a simple XML document of Countries/States, I thought I’d create a basic form that lets a user type in the first few characters of a state name and have the DataGrid filter its results. You’ll also notice that I had to do some not-so-tricky E4X filtering to extract only the American state names.

Full code after the jump.

Continue reading Filtering an XMLListCollection using the filterFunction property and regular expressions