Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Regular Expressions explained



This article will give you an introduction to the world of regular expressions. I'll start off with explaining what regular expressions are and introduce it's syntax, then some examples with varying complexity and last a list of tools which use regular expressions.

Concept

A regular expression is a text pattern consisting of a combination of alphanumeric characters and special characters known as metacharacters. A close relative is in fact the wildcard expression which are often used in file management. The pattern is used to match against text strings. The result of a match is either successful or not, however when a match is successful not all of the pattern must match, this is explained later in the article.

You'll find that regular expressions are used in three different ways: Regular text match, search and replace and splitting. The latter is basicly the same as the reverse match ie. everything the regular expression did not match.

Regular expressions are often simply called regexps or RE, but for consistency I'll be referring to it with it's full name.

Due to the versatility of the regular expression it is widely used in text processing and parsing. UNIX users are probably familiar with them trough the use of the programs, grep, sed, awk and ed. Text editors such as (X)Emacs and vi also use them heavily. Probably the most known use of regular expressions are in the programming language Perl, you'll find that Perl sports the most advanced regular expression implementation to this day.


| < 1 > | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next page >> | Printer-friendly page |

Comment List


Topic: Author:
Time:
help! what regex will not allow Email format like this "yaho Leary Tenorio 24.11.2008 07:50

but will allow

yahoo@yahoo.co
yahoo@yahoo.co.ph
yahoo@yahoo.com
yahoo@yahoo.com.ph


   RE: help! what regex will not allow Email format like this \ Nirmal Shah 29.12.2008 14:38

[Yy][\w]{4}\@[Yy][\w]{4}\.[\w\.]+


> but will allow
>
> yahoo@yahoo.co
> yahoo@yahoo.co.ph
> yahoo@yahoo.com
> yahoo@yahoo.com.ph


RegEx Required... Nirmal Shah 11.11.2008 16:57

I am not able to write RegEx for following string to catch...

IT_Manager_R&D_Division

I wanted catch following from above line.

IMRD

and wanted to ignore other parts.


what about usage of < and > assertion characters? Grzegorz Patynek 06.10.2008 13:45

what about usage of < and > assertion characters?


another great regexp tool S Church 01.03.2005 16:16

There's a free-as-in-beer development environment for Windows called HTML-Kit that's just great for writing scripts and web code. The Find or Find / Replace functions have a check box for Regexps, with a "Find All" button to highlight every instance matched by a regexp. The only drawback is that it assumes /is (case insensitivity and multiline).

VisualREGEXP mentioned in the article says it has no required supporting files, that the standalone executable is all that's needed. However, most Windows machines don't have the TCL/TK component "wish," which the README file claims is necessary for operation. Wish might be available somewhere online as a precompiled binary without having to install all of TCL/TK, but I'm not motivated enough to google it at the moment.


Email match David Robarts 15.01.2005 22:45

Some valid email addresses will fail this expression (and some invalid addresses pass).

[a-z0-9_-]+(.[a-z0-9_-]+)*@[a-z0-9_-]+(.[a-z0-9_-]+)+

The underscore character is not allowed in the domain part of the email address and some additional characters are allowed in the username part.

This might be better:

[a-z0-9_-]+(.[a-z0-9_-+]+)*@[a-z0-9-]+(.[a-z0-9-]+)+


   RE: Email match Nirmal Shah 11.11.2008 17:00

Majority of time we are using following regex for emails..

[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}

Try this.



> Some valid email addresses will fail this expression (and
> some invalid addresses pass).
>
> [a-z0-9_-]+(.[a-z0-9_-]+)*@[a-z0-9_-]+(.[a-z0-9_-]+)+
>
> The underscore character is not allowed in the domain part
> of the email address and some additional characters are
> allowed in the username part.
>
> This might be better:
>
> [a-z0-9_-]+(.[a-z0-9_-+]+)*@[a-z0-9-]+(.[a-z0-9-]+)+


can't see the graphic x x 02.11.2001 01:59

I can't see the graphic towards the bottom to demonstrate the usage of < >




Forgot your password?

Register a new user

Results

Polls