A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
Regular Expressions (regexp) Cheat Sheet
- .
- Match any character except NULL, empty string, or newline: (e.g. (…) matches ‘eN2′, ‘774′, ‘Akc’, etc, but not ‘ ‘)
- *
- Match preceding character 0 or more times: (e.g. ab*c matches ‘ac’, ‘abc’, ‘abbbc’, etc)
- +
- Match preceding character 1 or more times: (e.g. [hc]+at matches ‘hat’, ‘cat’, ‘chat’, ‘hcat’, ‘ccchat’ but not ‘at’)
- ?
- Match preceding character 0 or 1 time: (e.g. [hc]?at matches ‘hat’, ‘cat’, and ‘at’
- [characters]
- Match any characters within []: (e.g. [0-9a-zA-Z] matches all alphanumeric characters)
- ^(character class)
- Match all characters except those in character class: (e.g. [^abc] matches all characters except ‘a’, ‘b’, or ‘c’)
- -
- Create range of characters: (e.g. [0-9a-zA-Z] matches all alphanumeric characters)
- (pattern)
- Search for a subpattern: (e.g. [(fools)(fool's)] gold matches “fools gold” or “fool’s gold”)
- Escapes special character (e.g. . will treat a . as a literal period instead of parsing it’s special meaning)
- ^
- Matches the starting position within the string
- $
- Matches the ending position of the string
- {number}
- Match number of instances of preceding character
- {number,}
- Match number or more instances of preceding character
- {Number1,Number2}
- Match between Number1 and Number2 instances of preceding characters (inclusive)

