Found at: http://publish.ez.no/article/articleprint/11/ |
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.
[Note: Puppy has a regular expression evaluation and learning tool in the Utilities menu]
abc |
123 |
\ | ( ) [ { ^ $ * + ? . < > |
1.23 |
1x23 1 23 1-23 |
1\.23 |
* and + |
c* |
go |
c+ |
? |
cows? |
cow cows |
{n,m} |
{1,5} |
{1,} |
{5} |
^ and $ |
^The |
< and > |
cow |
cow coward cowage cowboy cowl |
( and ) |
( ?ho)+ |
ho ho ho ho ho ho hohoho |
| |
Bill|Linus|Steve|Larry |
cow(ard|age|boy|l)? |
cow coward cowage cowboy cowl |
((Donald|Dolly) Duck)|(Scrooge McDuck) |
[ and ] |
[a-z] |
[a-zA-Z0-9] |
<[a-zA-Z]+> |
cow Linus regular expression |
200 x-files C++ |
[^a-zA-Z0-9]+ |
\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] |
*.jpg |
*.[ch]pp |
.* |
*.jpg |
.*\.jpg |
ez*.[ch]pp |
ez.*\.[ch]pp |
ez.*\.(cpp|hpp) |
[a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+ |
("?[a-zA-Z]+"?[ \t]*)+\<[a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+\> |
[a-z]+:// |
^#include[ \t]+[<"][^>"]+[">] |
//.+$ |
/\*[^*]*\*/ |
-?[0-9]+\.[0-9]+ |
0x[0-9a-fA-F]+ |
grep -E "cow|vache" * >/dev/null && echo "Found a cow" |