Monday, January 17, 2011

Regular Expressions

Mastering Regular Expressions Gets You Babes/S...

Image by dberlind via Flickr

Today we are going to discuss regular expressions.

What are regular expressions (how do they differ from non-regular expressions?)

Here is a helpful definition from Wikipedia:

In computing, a regular expression, also referred to as regex or regexp, provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

Who Needs regular expressions?

Situations where regular expressions shine:

  • Say you have a long list of contacts in Last Name, First Name order. You want to switch the order, and loose the comma. This requires just one search and replace operation using regular expressions.
The above selling point for regex was adapted from the Bare Bones Software website. Bare Bones makes a free product called TextWrangler, that includes support for regular expressions, including the ability to search multiples files and directories.

Related articles

No comments: