PageRenderTime 118ms CodeModel.GetById 113ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/doc/users-guide/regexps.xml

#
XML | 131 lines | 128 code | 1 blank | 2 comment | 0 complexity | af2f1e42afc5d3c548d3d4da1e57732e MD5 | raw file
  1<!-- jEdit buffer-local properties: -->
  2<!-- :indentSize=1:noTabs=yes: -->
  3
  4<appendix id="regexps"><title>Regular Expressions</title>
  5 <para>
  6  jEdit uses regular expressions to implement inexact search and replace.
  7  A regular expression consists of a string where some
  8  characters are given special meaning with regard to pattern matching.
  9 </para>
 10 <para>
 11  Within a regular expression, the following characters have special meaning:
 12 </para>
 13 <bridgehead renderas="sect3">Positional Operators</bridgehead>
 14 <itemizedlist>
 15  <listitem><para><literal>^</literal> matches at the beginning of a line</para></listitem>
 16  <listitem><para><literal>$</literal> matches at the end of a line</para></listitem>
 17  <listitem><para><literal>\b</literal> matches at a word break</para></listitem>
 18  <listitem><para><literal>\B</literal> matches at a non-word break</para></listitem>
 19  <listitem><para><literal>\&lt;</literal> matches at the start of a word</para></listitem>
 20  <listitem><para><literal>\&gt;</literal> matches at the end of a word</para></listitem>
 21 </itemizedlist>
 22 <bridgehead renderas="sect3">One-Character Operators</bridgehead>
 23 <itemizedlist>
 24  <listitem><para><literal>.</literal> matches any single character</para></listitem>
 25  <listitem><para><literal>\d</literal> matches any decimal digit</para></listitem>
 26  <listitem><para><literal>\D</literal> matches any non-digit</para></listitem>
 27  <listitem><para><literal>\n</literal> matches the newline character</para></listitem>
 28  <listitem><para><literal>\s</literal> matches any whitespace character</para></listitem>
 29  <listitem><para><literal>\S</literal> matches any non-whitespace character</para></listitem>
 30  <listitem><para><literal>\t</literal> matches a horizontal tab character</para></listitem>
 31  <listitem><para><literal>\w</literal> matches any word (alphanumeric) character</para></listitem>
 32  <listitem><para><literal>\W</literal> matches any non-word (alphanumeric)
 33  character</para></listitem>
 34  <listitem><para><literal>\\</literal> matches the backslash
 35  (<quote>\</quote>) character</para></listitem>
 36 </itemizedlist>
 37 <bridgehead renderas="sect3">Character Class Operator</bridgehead>
 38 <itemizedlist>
 39  <listitem><para><literal>[<replaceable>abc</replaceable>]</literal> matches
 40  any character in
 41  the set <replaceable>a</replaceable>, <replaceable>b</replaceable> or
 42  <replaceable>c</replaceable></para></listitem>
 43  <listitem><para><literal>[^<replaceable>abc</replaceable>]</literal> matches
 44  any character not
 45  in the set <replaceable>a</replaceable>, <replaceable>b</replaceable> or
 46  <replaceable>c</replaceable></para></listitem>
 47  <listitem><para><literal>[<replaceable>a-z</replaceable>]</literal> matches
 48  any character in the
 49  range <replaceable>a</replaceable> to <replaceable>z</replaceable>, inclusive.
 50  A leading or trailing dash will be interpreted literally</para></listitem>
 51 </itemizedlist>
 52 <para>
 53  Within a character class expression, the following sequences have special meaning:
 54 </para>
 55 <itemizedlist>
 56  <listitem><para><literal>[:alnum:]</literal> Any alphanumeric
 57  character</para></listitem>
 58  <listitem><para><literal>[:alpha:]</literal> Any alphabetical character</para></listitem>
 59  <listitem><para><literal>[:blank:]</literal> A space or horizontal tab</para></listitem>
 60  <listitem><para><literal>[:cntrl:]</literal> A control character</para></listitem>
 61  <listitem><para><literal>[:digit:]</literal> A decimal digit</para></listitem>
 62  <listitem><para><literal>[:graph:]</literal> A non-space, non-control character</para></listitem>
 63  <listitem><para><literal>[:lower:]</literal> A lowercase letter</para></listitem>
 64  <listitem><para><literal>[:print:]</literal> Same as <literal>[:graph:]</literal>, but also space and tab</para></listitem>
 65  <listitem><para><literal>[:punct:]</literal> A punctuation character</para></listitem>
 66  <listitem><para><literal>[:space:]</literal> Any whitespace character, including newlines</para></listitem>
 67  <listitem><para><literal>[:upper:]</literal> An uppercase letter</para></listitem>
 68  <listitem><para><literal>[:xdigit:]</literal> A valid hexadecimal digit</para></listitem>
 69 </itemizedlist>
 70 <bridgehead renderas="sect3">Subexpressions and Backreferences</bridgehead>
 71 <itemizedlist>
 72  <listitem><para><literal>(<replaceable>abc</replaceable>)</literal> matches
 73  whatever the expression
 74  <replaceable>abc</replaceable> would match, and saves it as a subexpression.
 75  Also used for grouping</para></listitem>
 76  <listitem><para><literal>(?:<replaceable>...</replaceable>)</literal> pure
 77  grouping operator, does not
 78  save contents</para></listitem>
 79  <listitem><para><literal>(?#<replaceable>...</replaceable>)</literal> embedded
 80  comment, ignored by engine</para></listitem>
 81  <listitem><para><literal>(?=<replaceable>...</replaceable>)</literal> positive
 82  lookahead; the regular expression will match if the text in the brackets
 83  matches, but that text will not be considered part of the match</para></listitem>
 84  <listitem><para><literal>(?!<replaceable>...</replaceable>)</literal> negative
 85  lookahead; the regular expression will match if the text in the brackets
 86  does not
 87  match, and that text will not be considered part of the match</para></listitem>
 88  <listitem><para><literal>\<replaceable>n</replaceable></literal> where 0 &lt;
 89  <replaceable>n</replaceable> &lt; 10,
 90  matches the same thing the <replaceable>n</replaceable>th
 91  subexpression matched. Can only be used in the search string</para></listitem>
 92  <listitem><para><literal>$<replaceable>n</replaceable></literal> where 0 &lt;
 93  <replaceable>n</replaceable> &lt; 10,
 94  substituted with the text matched by the <replaceable>n</replaceable>th
 95  subexpression. Can only be used in the replacement string</para></listitem>
 96 </itemizedlist>
 97 <bridgehead renderas="sect3">Branching (Alternation) Operator</bridgehead>
 98 <itemizedlist>
 99  <listitem><para><literal><replaceable>a</replaceable>|<replaceable>b</replaceable></literal>
100  matches whatever the expression <replaceable>a</replaceable> would match, or whatever
101  the expression <replaceable>b</replaceable> would match.</para></listitem>
102 </itemizedlist>
103 <bridgehead renderas="sect3">Repeating Operators</bridgehead>
104 <para>
105  These symbols operate on the previous atomic expression.
106 </para>
107 <itemizedlist>
108  <listitem><para><literal>?</literal> matches the preceding expression or the
109  null string</para></listitem>
110  <listitem><para><literal>*</literal> matches the null string or any number of repetitions
111  of the preceding expression</para></listitem>
112  <listitem><para><literal>+</literal> matches one or more repetitions of the preceding
113  expression</para></listitem>
114  <listitem><para><literal>{<replaceable>m</replaceable>}</literal> matches exactly
115  <replaceable>m</replaceable>
116  repetitions of the one-character expression</para></listitem>
117  <listitem><para><literal>{<replaceable>m</replaceable>,<replaceable>n</replaceable>}</literal>
118  matches between
119  <replaceable>m</replaceable> and <replaceable>n</replaceable> repetitions of the preceding
120  expression, inclusive</para></listitem>
121  <listitem><para><literal>{<replaceable>m</replaceable>,}</literal> matches
122  <replaceable>m</replaceable> or more
123  repetitions of the preceding expression</para></listitem>
124 </itemizedlist>
125 <bridgehead renderas="sect3">Stingy (Minimal) Matching</bridgehead>
126 <para>
127  If a repeating operator (above) is immediately followed by a
128  <literal>?</literal>, the repeating operator will stop at the smallest
129  number of repetitions that can complete the rest of the match.
130 </para>
131</appendix>