Appendix E. Regular Expressions
Prev | Part I. Using jEdit | Next

## Appendix E. Regular Expressions

jEdit uses regular expressions to implement inexact search and replace. A regular expression consists of a string where some characters are given special meaning with regard to pattern matching.

Within a regular expression, the following characters have special meaning:

### Positional Operators

- `^` matches at the beginning of a line

- `$` matches at the end of a line

- `\b` matches at a word break

- `\B` matches at a non-word break

- `\<` matches at the start of a word

- `\>` matches at the end of a word

### One-Character Operators

- `.` matches any single character

- `\d` matches any decimal digit

- `\D` matches any non-digit

- `\n` matches the newline character

- `\s` matches any whitespace character

- `\S` matches any non-whitespace character

- `\t` matches a horizontal tab character

- `\w` matches any word (alphanumeric) character

- `\W` matches any non-word (alphanumeric) character

- `\\` matches the backslash (“\”) character

### Character Class Operator

- `[`abc`]` matches any character in the set `a`, `b` or `c`

- `[^`abc`]` matches any character not in the set `a`, `b` or `c`

- `[`a-z`]` matches any character in the range `a` to `z`, inclusive. A leading or trailing dash will be interpreted literally

- `[[:alnum:]]` matches any alphanumeric character

- `[[:alpha:]]` matches any alphabetical character

- `[[:blank:]]` matches a space or horizontal tab

- `[[:cntrl:]]` matches a control character

- `[[:digit:]]` matches a decimal digit

- `[[:graph:]]` matches a non-space, non-control character

- `[[:lower:]]` matches a lowercase letter

- `[[:print:]]` same as `[[:graph:]]`, but also space and tab

- `[[:punct:]]` matches a punctuation character

- `[[:space:]]` matches any whitespace character, including newlines

- `[[:upper:]]` matches an uppercase letter

- `[[:xdigit:]]` matches a valid hexadecimal digit

### Subexpressions and Backreferences

- `(`abc`)` matches whatever the expression `abc` would match, and saves it as a subexpression. Also used for grouping

- `(?:`...`)` pure grouping operator, does not save contents

- `(?#`...`)` embedded comment, ignored by engine

- `(?=`...`)` positive lookahead; the regular expression will match if the text in the brackets matches, but that text will not be considered part of the match

- `(?!`...`)` negative lookahead; the regular expression will match if the text in the brackets does not match, and that text will not be considered part of the match

- `\`n`` where 0 < `n` < 10, matches the same thing the `n`th subexpression matched. Can only be used in the search string

- `$`n`` where 0 < `n` < 10, substituted with the text matched by the `n`th subexpression. Can only be used in the replacement string

### Branching (Alternation) Operator

- ``a`|`b`` matches whatever the expression `a` would match, or whatever the expression `b` would match.

### Repeating Operators

These symbols operate on the previous atomic expression.

- `?` matches the preceding expression or the null string

- `*` matches the null string or any number of repetitions of the preceding expression

- `+` matches one or more repetitions of the preceding expression

- `{`m`}` matches exactly `m` repetitions of the one-character expression

- `{`m`,`n`}` matches between `m` and `n` repetitions of the preceding expression, inclusive

- `{`m`,}` matches `m` or more repetitions of the preceding expression

### Stingy (Minimal) Matching

If a repeating operator (above) is immediately followed by a `?`, the repeating operator will stop at the smallest number of repetitions that can complete the rest of the match.

Prev | Up | Next
Appendix D. Glob Patterns | Home | Appendix F. Macros Included With jEdit