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



Wildcards

For people who has some knowledge with wildcards I'll give a brief explanation on how to convert them to regular expressions. After reading this article you probably have seen the similarities with wildcards. For instance

*.jpg

matches any text which end with .jpg. You can also specify brackets with characters, for instance

*.[ch]pp

matches any text which ends in .cpp or .hpp. Altogether very similar to regular expressions.

Converting the * operator

The * means match zero or more of anything in wildcards, as we learned we do this is regular expression with the punctuation mark and the * quantifier. This gives

.*

Also remember to convert any punctuation marks from wildcards to be backslashified.

Converting the ? operator

The ? means match any character but do match something, this is exactly what the punctuation mark does.

Converting the [] operator

The square bracket can be used untouched since they have the same meaning going from wildcards to regular expressions.

These leaves us with:
Replace any * characters with .*
Replace any ? characters with .
Leave square brackets as they are.
Replace any characters which are metacharacters with a backslashified variant.

Examples


*.jpg

would be converted to

.*\.jpg



ez*.[ch]pp

would be convert to

ez.*\.[ch]pp

or alternatively

ez.*\.(cpp|hpp)



<< 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