spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column5


Unix Regular Expressions

Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use

What are RegExps?

RegExps, shorthand for regular expressions, are used in pattern matching and substitution operators. Regular expressions are actually a grammer for a little language. The regular expression interpreter (which we'll call the Engine) takes your grammer and compares it with the string you're doing pattern matching on. The Engine then returns a Boolean value, which depends on whether or not the string can be parsed as a sentence of your little language.

A regular expression is really just a sequence or a pattern of characters that is matched against a string of text when performing searches and replacements. A simple regular expression consists of a single character or a set of characters that matches itself.

Regexps are a very powerful tool. They pack a lot of meaning into a short space. Every single character in a regular expression has a special meaning. I once wasted several hours trying to fix a Perl script, only to find out later that I had forgotten a little "?", somewhere in one of the regular expressions I had constructed.

Many tasks can be done with regular expressions. The most common one is to find out whether a given string matches a particular pattern. You can also find out where the matching substring is located within the string. You can use a substitution command to replace matching sections with another string of your choice. The split() operator returns an array of all substrings your pattern did not match.

Don't worry if you still don't quite understand what regexps are. You'll soon become a regular expression expert.

http://www.internet.com

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Created: October 23, 1997, 1997
Revised: December 4, 1997
URL: http://www.webreference.com/js/column5/regular.html