|
| |
- See
EasyPatterns for patterns that are easy for humans to read, like [ 3
letters, 2 or more digits ]
Some Basic Regular Expression Search Examples
| What to Match |
Operator |
Examples |
| Any single character |
. |
g.t matches get, got,
gut, together, g-t |
| Any string of characters (one or more) |
+ |
w+e matches were, wwezaa,
wwwe.write (longest possible match is used) |
| Any string of characters (or none) |
* |
w*e matches were, were, wwezaa,
wwwe.write (longest
possible match is used) |
| One of the specified characters |
[] |
g[eo]t matches get and got
but not gut |
| One of the characters in a range |
[-] |
[b-p]at matches bat, cat,
fat, hat, mat but not rat or sat |
| One expression or another |
(|) |
W(in|indows) matches Win or
Windows |
| One or more expressions |
()+ |
(at)+ matches atat in catatonic
and at in battle |
| All characters (perhaps on different lines) |
.* |
h.*d matches helped, Hello
World, & Hello (cr lf) Win95 World. |
| Two strings nearby (perhaps on different lines) |
.* |
the[\0-’]*first matches the first
and the (cr lf) very first |
| One of the characters not in a range |
[^-] |
[^b-p]at matches at in rat
& sat and nothing in bat, cat, fat, hat. |
| Find all words of length x |
|
[^\w]\w\w\w+ will find all 3
letter words,
[^\w]a\w\w\w\w finds all 5 letter words starting with 'a'. |
Additional Regular Expression Search Examples
| Search String |
Match |
| L. |
line, list, lane, LogVar1
(when case sensitive is off) |
| [on][on] |
non, no, on |
| \[ |
[ |
| [a-z]+ |
abcdefghijklomopqrstuvwxyz
Note: If used with Case Sensitive off, it will also match ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| [a-zA-ZĄ-’] |
Matches the same as the +[a-z] example above (regardless
of case sensitive flag) and also all other special characters for Western European
languages. |
| (one|two|three) |
one, two, three |
| (one|two|three)+ |
one, onetwo, twothree |
| Windows[\0-’]*95 |
Will match up to 4096 characters (on several lines) between Windows and
95. |
| All .* replaces |
all the replaces (the .* character matches all chars) |
| /\*[\0-’]*\*/ |
Matches C style comments on several lines if necessary (up
to 4096
characters) |
| 01*[0-9].htm |
01346.htm, 01.htm, 016965.htm |
| [ab]*c |
c, abc, bac, abbc,
bbac |
| .include (<|\[)+[a-z0-9_].h*(p)+[\]>]
|
Matches:
#include [stdafx.h]
#include <dos.h>
#include [my_include.hpp]
#include [sr32.h] |
See also
Regular expressions
|