Construct | Matches |
---|---|

Characters | |

x |
The character x |

\ | The backslash character |

\0n |
The character with octal value 0n (0 <= n <,= 7) |

\0nn |
The character with octal value 0nn (0 <= n <,= 7) |

\0mnn |
The character with octal value 0mnn (0 <= m <= 3,0 <= n <,= 7) |

\xhh |
The character with hexadecimal value 0xhh |

\uhhhh |
The character with hexadecimal value 0xhhhh |

\t | The tab character |

\n | The newline (line-feed) character |

\r | The carriage-return character |

\f | The form-feed character |

\a | The alert (bell) character |

\e | The escape character |

\cX |
The control character corresponding to X |

Characters classes | |

[abc] | a,b or c (simple class) |

[^abc] | Any character except a,b or c (negation) |

[a-zA-Z] | a through z or A through Z, inclusive (range) |

[a-d[m-p]] | a through d, or m through p: [a-dm-p] inclusive (union) |

[a-z&&[def]] | d, e or f (intersection) |

[a-z&&[^bc]] | a through z, except for b and c: [ad-z] (subtraction) |

[a-z&&[^m-p]] | a through z, and not m through p: [a-lq-z] (subtraction) |

Predefined characters classes | |

. | Any character |

\d | A digit: [0-9] |

\D | A non-digit: [^0-9] |

\s | A whitespace character: [ \t\n\x0B\f\r] |

\S | A non-whitespace character: [^\s] |

\w | A word character: [a-zA-Z_0-9] |

\W | A non-word character: [^\w] |

Boundary matchers | |

^ | The beginning of a line |

$ | The end of a line |

\b | A word boundary |

\B | A non-word boundary |

\A | The beginning ot the input |

\G | The end of the previous match |

\Z | The end ot the input but for the final terminator, if any |

\z | The end ot the input |

Greedy quantifiers | |

X? |
X, once or not at all |

X* |
X, zero or more times |

X+ |
X, one or more times |

X{n} |
X, exactly n times |

X{n,} |
X, at least n times |

X{n,p} |
X, at least n times, but not more than p times |

Reluctant quantifiers | |

X?? |
X, once or not at all |

X*? |
X, zero or more times |

X+? |
X, one or more times |

X{n}? |
X, exactly n times |

X{n,}? |
X, at least n times |

X{n,p}? |
X, at least n times, but not more than p times |

Possessive quantifiers | |

X?+ |
X, once or not at all |

X*+ |
X, zero or more times |

X++ |
X, one or more times |

X{n}+ |
X, exactly n times |

X{n,}+ |
X, at least n times |

X{n,p}+ |
X, at least n times, but not more than p times |

Logical operators | |

XY |
X followed by Y |

X|Y |
Either X or Y |

(X) |
X, as a capturing group |

Back references | |

\n |
Whatever the n^{th} capturing group matched |

Quotation | |

\ | Nothing, but quotes the following character |

\Q | Nothing, but quotes all characters until \E |

\E | Nothing, but ends quoting started by \Q |

Special constructs (non-capturing) | |

(?:X) |
X, as a non-capturing group |

(?=X) |
X, via zero-width positive lookahead |

(?!X) |
X, via zero-width negative lookahead |

(?<=X) |
X, via zero-width positive lookbehind |

(?<!X) |
X, via zero-width negative lookbehind |

(?>X) |
X, as an independent, non-capturing group |