

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 25
Warning: include(http://www.unix-manuals.com/topad.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 25
Warning: include() [function.include]: Failed opening 'http://www.unix-manuals.com/topad.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 25
NOTICE - New forum for all UNIX learners, users and programmers - click here
Although the term "Regular Expression" sounds tedious, and even competent UNIX® programmers
often only have a vague idea of what they are, these are undoubtably the single most powerful 'feature' of UNIX.
They are used (in various forms) in programs ranging from 'ls', through 'grep', 'emacs' and 'awk', to programming
languages like 'python' and 'perl'. In short, if you are using UNIX seriously, you will certainly be using regular
expressions.
This reference guide presents the main regular expression meta-characters. We may later extend this to include
more detailed information about the different 'dialects' that various commands and languages use.
Regular Expression Metacharacters
| . (dot) |
Any one character |
| [...] |
Any one of the characters within the square brackets |
| [^...] |
Any one of the characters not within the square brackets |
| ^ |
Start of line |
| $ |
End of line |
| \< |
Start of word |
| /> |
End of word |
| | (certical bar) |
Separates two expressions, matches either |
| ? |
Previous character (or group) is optional |
| + |
One or more of the previous character (or group) |
| * |
Any number (including none) of the previous character (or group) NOTE: Matches as many as possible |
| ( ) |
Three uses:
1: Used to enclose a pair of expressions, separated by | (vertical bar - see above)
2: Grouping for quantifiers ('?', '+', and '*' - see above)
3: Carry some text that matches the expression within (see '\1', etc, below) |
| \1 (and \2, \3, etc) |
Output the text 'carried forward' by the brackets (see '( )' above). |
Note: When working with regular expressions, you may also find our ASCII
Table useful.
A bit more detail!
What we have listed above is a very basic listing of the main 'regex' metacharacters. It is not intended to
be anything more than that. It is hard to know how to expand it further without turning into a full-blown tutorial.
Nearly all tutorials we have seen are seriously lacking, and we don't intend to add to their number!
Instead, we recommend the following book. What's more, we recommend this book more highly than any other book
you'll find on this web site. There are two main reasons for this:
- The subject matter. As we said earlier, regular expressions are so deeply ingrained in the whole philosophy
of UNIX, that it is impossible to be an 'industrial grade' UNIX programmer without a really deep understanding
of regular expressions. Also, the gap between knowing the metacharacters above, and really understanding how to
weild them, is greater than for any other language or syntax we can think of.
- The style of the book. Surprising for a book on such a potentially dry subject, this is the most readable computer
book we've seen for a very long time. Regular expressions are made interesting, and their use is constantly related
to real-life problems. You will often find yourself thinking, "I wish I'd known that before - I wrote an entire
program to do that"! You will probably also find yourself reading this book cover-to-cover, which is in itself
unusual for such a technical book.
In short, if you only buy one book this year, buy this one!
Recommended book: 'Mastering Regular Expressions: Powerful Techniques for Perl and Other Tools',
by Jeffrey E. F. Friedl, published by O'Reilly. You can order the book directly from here. Click here
to order from Amazon.co.uk in the UK, or here
to order from Amazon.com in the USA
|

(UK)
|

(USA)
|

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 179
Warning: include(http://www.unix-manuals.com/botad.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 179
Warning: include() [function.include]: Failed opening 'http://www.unix-manuals.com/botad.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /home/2332/unix-man/www.unix-manuals.com/public_html/refs/regex/regex.htm on line 179
© Copyright 2000-2001, Tom Reader, All Rights Reserved.
UNIX is a registered trademark of The Open Group in the US and other countries.
For more information on the use of the UNIX trademark, click
here.
The contents of this site are not connected with or endorsed by The Open Group in any way.