/www/tags/NOV_07_2009/htdocs/users-guide/regexps.html
HTML | 63 lines | 63 code | 0 blank | 0 comment | 0 complexity | b7c6f09a9363438ea8b468e9d616e4a4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Appendix E. Regular Expressions</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="using-jedit-part.html" title="Part I. Using jEdit"><link rel="prev" href="globs.html" title="Appendix D. Glob Patterns"><link rel="next" href="macro-index.html" title="Appendix F. Macros Included With jEdit"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix E. Regular Expressions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="globs.html">Prev</a> </td><th width="60%" align="center">Part I. Using jEdit</th><td width="20%" align="right"> <a accesskey="n" href="macro-index.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="regexps"></a>Appendix E. Regular Expressions</h2></div></div></div><p>jEdit 4.3pre5 and later uses regular expressions from <a class="ulink" href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html" target="_top">java.util.regex.Pattern</a>
- to implement inexact search and replace. Click there to see a complete
- reference guide to all supported meta-characters.</p><p>A regular expression consists of a string where some characters are
- given special meaning with regard to pattern matching.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Inside XML files</h3><p>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.</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Inside Java / beanshell / properties files</h3><p>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 (<code class="literal">\\</code>)</p></div><p>Within a regular expression, the following characters have special
- meaning:</p><h4><a name="id2579273"></a>Positional Operators</h4><div class="itemizedlist"><ul type="disc"><li><p><code class="literal">^</code> matches at the beginning of a line</p></li><li><p><code class="literal">$</code> matches at the end of a line</p></li><li><p><code class="literal">\B</code> matches at a non-word break</p></li><li><p><code class="literal">\b</code> matches at a word boundary</p></li></ul></div><h4><a name="id2579327"></a>One-Character Operators</h4><div class="itemizedlist"><ul type="disc"><li><p><code class="literal">.</code> matches any single character</p></li><li><p><code class="literal">\d</code> matches any decimal digit</p></li><li><p><code class="literal">\D</code> matches any non-digit</p></li><li><p><code class="literal">\n</code> matches the newline character</p></li><li><p><code class="literal">\s</code> matches any whitespace character</p></li><li><p><code class="literal">\S</code> matches any non-whitespace
- character</p></li><li><p><code class="literal">\t</code> matches a horizontal tab
- character</p></li><li><p><code class="literal">\w</code> matches any word (alphanumeric)
- character</p></li><li><p><code class="literal">\W</code> matches any non-word (alphanumeric)
- character</p></li><li><p><code class="literal">\\</code> matches the backslash (“<span class="quote">\</span>”)
- character</p></li></ul></div><h4><a name="id2580272"></a>Character Class Operator</h4><div class="itemizedlist"><ul type="disc"><li><p><code class="literal">[<em class="replaceable"><code>abc</code></em>]</code> matches
- any character in the set <em class="replaceable"><code>a</code></em>,
- <em class="replaceable"><code>b</code></em> or <em class="replaceable"><code>c</code></em></p></li><li><p><code class="literal">[^<em class="replaceable"><code>abc</code></em>]</code> matches
- any character not in the set <em class="replaceable"><code>a</code></em>,
- <em class="replaceable"><code>b</code></em> or <em class="replaceable"><code>c</code></em></p></li><li><p><code class="literal">[<em class="replaceable"><code>a-z</code></em>]</code> matches
- any character in the range <em class="replaceable"><code>a</code></em> to
- <em class="replaceable"><code>z</code></em>, inclusive. A leading or trailing dash
- will be interpreted literally</p></li></ul></div><h4><a name="id2580352"></a>Subexpressions and Backreferences</h4><div class="itemizedlist"><ul type="disc"><li><p><code class="literal">(<em class="replaceable"><code>abc</code></em>)</code> matches
- whatever the expression <em class="replaceable"><code>abc</code></em> would match,
- and saves it as a subexpression. Also used for grouping</p></li><li><p><code class="literal">(?:<em class="replaceable"><code>...</code></em>)</code> pure
- grouping operator, does not save contents</p></li><li><p><code class="literal">(?#<em class="replaceable"><code>...</code></em>)</code> embedded
- comment, ignored by engine</p></li><li><p><code class="literal">(?=<em class="replaceable"><code>...</code></em>)</code> 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</p></li><li><p><code class="literal">(?!<em class="replaceable"><code>...</code></em>)</code> 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</p></li><li><p><code class="literal">\<em class="replaceable"><code>n</code></em></code> where 0 <
- <em class="replaceable"><code>n</code></em> < 10, matches the same thing the
- <em class="replaceable"><code>n</code></em>th subexpression matched. Can only be
- used in the search string</p></li><li><p><code class="literal">$<em class="replaceable"><code>n</code></em></code> where 0 <
- <em class="replaceable"><code>n</code></em> < 10, substituted with the text
- matched by the <em class="replaceable"><code>n</code></em>th subexpression. Can
- only be used in the replacement string</p></li></ul></div><h4><a name="id2580494"></a>Branching (Alternation) Operator</h4><div class="itemizedlist"><ul type="disc"><li><p><code class="literal"><em class="replaceable"><code>a</code></em>|<em class="replaceable"><code>b</code></em></code>
- matches whatever the expression <em class="replaceable"><code>a</code></em> would
- match, or whatever the expression <em class="replaceable"><code>b</code></em> would
- match.</p></li></ul></div><h4><a name="id2580527"></a>Repeating Operators</h4><p>These symbols operate on the previous atomic expression.</p><div class="itemizedlist"><ul type="disc"><li><p><code class="literal">?</code> matches the preceding expression or the
- null string</p></li><li><p><code class="literal">*</code> matches the null string or any number of
- repetitions of the preceding expression</p></li><li><p><code class="literal">+</code> matches one or more repetitions of the
- preceding expression</p></li><li><p><code class="literal">{<em class="replaceable"><code>m</code></em>}</code> matches
- exactly <em class="replaceable"><code>m</code></em> repetitions of the
- one-character expression</p></li><li><p><code class="literal">{<em class="replaceable"><code>m</code></em>,<em class="replaceable"><code>n</code></em>}</code>
- matches between <em class="replaceable"><code>m</code></em> and
- <em class="replaceable"><code>n</code></em> repetitions of the preceding
- expression, inclusive</p></li><li><p><code class="literal">{<em class="replaceable"><code>m</code></em>,}</code> matches
- <em class="replaceable"><code>m</code></em> or more repetitions of the preceding
- expression</p></li></ul></div><h4><a name="id2580641"></a>Stingy (Minimal) Matching</h4><p>If a repeating operator (above) is immediately followed by a
- <code class="literal">?</code>, the repeating operator will stop at the smallest
- number of repetitions that can complete the rest of the match.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">On regex search</h3><p>There are some known issues with the
- <code class="literal">java.util.regex</code> 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
- <code class="literal">gnu.regexp</code> library. If you find that
- <code class="literal">gnu.regexp</code>, used in jEdit 4.2 and earlier, is
- more suitable for your search/replace needs, you can try the
- <span class="bold"><strong>XSearch plugin</strong></span>, which still
- uses it and can provide a replacement to the built-in search
- dialog.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="globs.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="using-jedit-part.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="macro-index.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Appendix D. Glob Patterns </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix F. Macros Included With jEdit</td></tr></table></div></body></html>