PageRenderTime 177ms CodeModel.GetById 173ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/doc/users-guide/globs.xml

#
XML | 137 lines | 107 code | 27 blank | 3 comment | 0 complexity | e235829d7cced2c541761624033ef9b8 MD5 | raw file
  1<?xml version="1.0" encoding="UTF-8"?>
  2<appendix id="globs">
  3    <title>Glob Patterns</title>
  4
  5    <!-- jEdit buffer-local properties: -->
  6
  7    <!-- :indentSize=1:noTabs=true: -->
  8
  9    <!-- :xml.root=users-guide.xml: -->
 10
 11    <para>jEdit uses glob patterns similar to those in the various Unix shells
 12    to implement file name filters in the file system browser. Glob patterns
 13    resemble regular expressions somewhat, but have a much simpler syntax. The
 14    following character sequences have special meaning within a glob
 15    pattern:</para>
 16
 17    <itemizedlist>
 18        <listitem>
 19            <para><literal>?</literal> matches any one character</para>
 20        </listitem>
 21
 22        <listitem>
 23            <para><literal>*</literal> matches any number of characters</para>
 24        </listitem>
 25
 26        <listitem>
 27            <para><literal>{!<replaceable>glob</replaceable>}</literal> Matches
 28            anything that does <emphasis>not</emphasis> match
 29            <replaceable>glob</replaceable></para>
 30        </listitem>
 31
 32        <listitem>
 33            <para><literal>{<replaceable>a</replaceable>,<replaceable>b</replaceable>,<replaceable>c</replaceable>}</literal>
 34            matches any one of <replaceable>a</replaceable>,
 35            <replaceable>b</replaceable> or <replaceable>c</replaceable></para>
 36        </listitem>
 37
 38        <listitem>
 39            <para><literal>[<replaceable>abc</replaceable>]</literal> matches
 40            any character in the set <replaceable>a</replaceable>,
 41            <replaceable>b</replaceable> or <replaceable>c</replaceable></para>
 42        </listitem>
 43
 44        <listitem>
 45            <para><literal>[^<replaceable>abc</replaceable>]</literal> matches
 46            any character not in the set <replaceable>a</replaceable>,
 47            <replaceable>b</replaceable> or <replaceable>c</replaceable></para>
 48        </listitem>
 49
 50        <listitem>
 51            <para><literal>[<replaceable>a-z</replaceable>]</literal> matches
 52            any character in the range <replaceable>a</replaceable> to
 53            <replaceable>z</replaceable>, inclusive. A leading or trailing dash
 54            will be interpreted literally</para>
 55        </listitem>
 56    </itemizedlist>
 57
 58    <para>Since we use <literal>java.util.regex</literal> patterns to implement
 59    globs, this means that in addition to the above, a number of
 60    <quote>character class metacharacters</quote> may be used. Keep in mind,
 61    their usefulness is limited since the regex quantifier metacharacters
 62    (asterisk, questionmark, and curly brackets) are redefined to mean something
 63    else in filename glob language, and the regex quantifiers are not available
 64    in glob language.</para>
 65
 66    <itemizedlist>
 67        <listitem>
 68            <para><literal>\w</literal> matches any alphanumeric character or
 69            underscore</para>
 70        </listitem>
 71
 72        <listitem>
 73            <para><literal>\s</literal> matches a space or horizontal tab</para>
 74        </listitem>
 75
 76        <listitem>
 77            <para><literal>\S</literal> matches a printable
 78            non-whitespace.</para>
 79        </listitem>
 80
 81        <listitem>
 82            <para><literal>\d</literal> matches a decimal digit</para>
 83        </listitem>
 84    </itemizedlist>
 85
 86    <para>Here are some examples of glob patterns:</para>
 87
 88    <itemizedlist>
 89        <listitem>
 90            <para><userinput>*</userinput> - all files.</para>
 91        </listitem>
 92
 93        <listitem>
 94            <para><userinput>*.java</userinput> - all files whose names end with
 95            <quote>.java</quote>.</para>
 96        </listitem>
 97
 98        <listitem>
 99            <para><userinput>*.[ch]</userinput> - all files whose names end with
100            either <quote>.c</quote> or <quote>.h</quote>.</para>
101        </listitem>
102
103        <listitem>
104            <para><userinput>*.{c,cpp,h,hpp,cxx,hxx}</userinput> - all C or C++
105            files.</para>
106        </listitem>
107
108        <listitem>
109            <para><userinput>[^#]*</userinput> - all files whose names do not
110            start with <quote>#</quote>.</para>
111        </listitem>
112    </itemizedlist>
113
114    <bridgehead>Using regexes instead of globs</bridgehead>
115
116    <para>Sometimes it is desirable to use a regular expression instead of a
117    glob for specifying file sets. This is because regular expressions are more
118    powerful than globs and can provide the user with more specific filename
119    matching criteria. To avoid the glob-to-regex transformation, prefix your
120    pattern with the string <literal>(re)</literal>, which will tell jEdit to
121    not translate the following pattern into a regex (since it already is one).
122    For example:</para>
123
124    <glosslist>
125        <glossentry>
126            <glossterm><literal> (re).*\.(h|c(c|pp)?) </literal></glossterm>
127
128            <glossdef>
129                <para>Matches *.c, *.cpp, *.h, *.cc</para>
130            </glossdef>
131        </glossentry>
132    </glosslist>
133
134    <para>If you need to match files that begin with the glob-translate-disable
135    prefix <literal>(re)</literal>, you can escape it with a leading backslash
136    and the metacharacters will be translated into globs as before.</para>
137</appendix>