jEdit 4.3pre5 and later uses regular expressions from java.util.regex.Pattern to implement inexact search and replace. Click there to see a complete reference guide to all supported meta-characters.
A regular expression consists of a string where some characters are given special meaning with regard to pattern matching.
Inside XML files (such as Jedit mode files), it is important that you escape XML special characters, such as &, <, >, etc. You can use the XML plugin's "characters to entities" to perform this mapping.
Java strings are always parsed by java before they are processed
by the regular expression engine, so you must make sure that backslashes
are escaped by an extra backslash (\\
)
Within a regular expression, the following characters have special meaning:
^
matches at the beginning of a line
$
matches at the end of a line
\B
matches at a non-word break
\b
matches at a word boundary
.
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
[
matches
any character in the set abc
]a
,
b
or c
[^
matches
any character not in the set abc
]a
,
b
or c
[
matches
any character in the range a-z
]a
to
z
, inclusive. A leading or trailing dash
will be interpreted literally
(
matches
whatever the expression abc
)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...
)
\
where 0 <
n
n
< 10, matches the same thing the
n
th subexpression matched. Can only be
used in the search string
$
where 0 <
n
n
< 10, substituted with the text
matched by the n
th subexpression. Can
only be used in the replacement string
matches whatever the expression a
|b
a
would
match, or whatever the expression b
would
match.
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
{
matches
exactly m
}m
repetitions of the
one-character expression
{
matches between m
,n
}m
and
n
repetitions of the preceding
expression, inclusive
{
matches
m
,}m
or more repetitions of the preceding
expression
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.
There are some known issues with the
java.util.regex
library, as it stands in
Sun's Java 1.5 and 1.6. In particular, it is possible to create
regular expressions that hang the JVM, or cause stack overflow
errors, which was not as easy to accomplish using the legacy
gnu.regexp
library. If you find that
gnu.regexp
, used in jEdit 4.2 and earlier, is
more suitable for your search/replace needs, you can try the
XSearch plugin, which still
uses it and can provide a replacement to the built-in search
dialog.