Chapter 12. Regular Expressions

FEATURED CLASSES

  • RegExp

A lot of the work a program does is in getting and processing information from an outside source, no matter whether the source is a file, a web site, a service, a stored object, or user input. You have to extract or manipulate the information that the input contains, so ActionScript 3.0 gives you specialized tools for working with certain kinds of data. In Chapter 11, "XML and E4X," you saw that ActionScript 3.0 has a special syntax for dealing with XML data, so when you get XML from an external source, you can count yourself lucky and use E4X to interpret and manipulate it easily. A lot of the time you aren't so lucky, and the input you have to deal with uses a format ActionScript 3.0 doesn't support, or it's free-form. To help you deal with any kind of textual data, ActionScript 3.0 includes native support for regular expressions.

Introducing Regular Expressions

Regular expressions are fantastically cool. They are little programs inside your own program, written in their own concise language. You can store them and use them over and over. You can use them to search through text, extract just the parts you want from a bigger piece of text, or replace parts of text.

With regular expressions, you can handle any kind of text with a regular grammar, from HTML to LaTeX, Markdown to DTDs. You can use these expressions to create lexers, programs that break down a blob of text into discrete elements, like breaking an English sentence into ...

Get ActionScript 3.0 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.