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



Sequences

Last we have sequences which defines sequences of characters which can match, sometimes you don't want match a word directly but rather something that resembles one. The sequence characters are

[ and ]

any characters put inside the sequence brackets are treated as a literal character, even metacharacters. The only special characters are the - which denotes character ranges and the ^ which is used to negate a sequence. The sequence is somewhat similar with alternation, the similarity is that only one of the items listed will match. For instance

[a-z]

will match any small characters which are in the English alphabet (a to z). Another common sequence is

[a-zA-Z0-9]

which matches any small or capital characters in the English alphabet as well as numbers. Sequences are also mixed with quantifiers and assertions to produce more elaborate searches. For instance

<[a-zA-Z]+>

matches all whole words. This will match

cow
Linus
regular
expression

but will not match

200
x-files
C++

Now what if you wanted to find anything but words, the expression

[^a-zA-Z0-9]+

would find any sequences of characters which does not contain the English alphabet or any numbers.

Some implementations of regular expressions allows you to use shorthand versions for commonly used sequences, they are:

\d, a digit [0-9]
\D, a non-digit [^0-9]
\w, a word (alphanumeric) [a-zA-Z0-9]
\W, a non-word [^a-zA-Z0-9]
\s, a whitespace [ \t\n\r\f]
\S, a non-whitespace [^ \t\n\r\f]


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

Comment List


Topic: Author:
Time:
Word search usin Regexp vipul Sathavra 18.09.2009 11:31

i want to search two word in string,so the second word is come away from 20 word or less from first word.

somthing like:

dog........(20 word with . , '' : number and other char).........Food

or

Food........(20 word with . , '' : number and other char).........Dog

please understand this and give some Reg Exp solution

thank you,


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