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



Assertions

The next type of metacharacters are assertions, these will match if a given assertion is true. The first pair of assertions are

^ and $

which match the beginning of the line and the end of the line. Note that some regular expression implementations allows you to change their behavior so that they will instead match the beginning of the text and the end of the text. These assertions always match a zero length string, or in other words they match a position. For instance if you wrote this expression:

^The

it would match any line which began with the word The.

The next assertion characters match at the beginning and end of a word, they are:

< and >

they come in handy when you want to match a word precisely, for instance:

cow

would match any of the following words

cow
coward
cowage
cowboy
cowl

a small change to the expression:

and you'll only match the word cow in the text.

One last thing to be said is that all literal characters are in fact assertions themselves, the difference between them and the ones above is that literal ones has a size. So for cleanliness sake we only use the word assertions for those that are zero-width.


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

Comment List


Topic: Author:
Time:
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-]+)+


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