Regular Expressions: An Introduction
by Amit Arora
Published: January 12, 2004
User Rating: 8.9 (256 votes)

Page Page » 1 2 3 4 5 6 7 8 9

What is a regular expression ?

"A regular expression is a pattern that is matched against a subject string from left to right". Well, that was textbook answer. But in simple terms, regular expression is a string used for find and replacing strings in other large strings.

You can even say that regular expression (a.k.a regex or regexp) are fourth generation (4G) wilcards, that we used in the good ol' days of DOS.

(But don't say that I said so, otherwise those perl experts are going to bite my head off for this remark. Why ? Because ... regexp are so powerful, yet easy to use, and saying that they are just wilcard, would be an insult. So i didn't say it, ok)

Why use regular expression ?

Hello ... ?!? Are you paying attention. I just said it, they are powerful and easy to use, that is why! Ok, seriouly, if you are serious about web development, you will have to use them one time or other be it in JavaScript, PHP, Python, Perl (mother of all web development regexps), Ruby or even in Apache configuration. So it is advised to have a basic knowledge of the regular expressions.

Example

In the good old dos prompt, typing

dir *

would actually display all the files. Meaning the pattern * means "match anything".

So if you were to write this is in the regular expression, you would write

/.*/m

Explaination

/ Start Pattern . Find any character * Find any number of times / End Pattern m Match the pattern in multi-line mode
Page Page » 1 2 3 4 5 6 7 8 9

About

Amit Arora is web developer with expertise in developing eCommerce enabled websites for the businesses.

Contact | Resume

Subscribe to newsletter




Get Firefox

Monitored by Site24x7
Uptime