PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/www/tags/NOV_07_2009/htdocs/42docs/users-guide/regexps.xml

#
XML | 127 lines | 123 code | 1 blank | 3 comment | 0 complexity | c65f8e6d59d3f65c31c3ca80f857e8c2 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
  1. <!-- jEdit buffer-local properties: -->
  2. <!-- :indentSize=1:noTabs=yes: -->
  3. <!-- :xml.root=users-guide.xml: -->
  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. <listitem><para><literal>[[:alnum:]]</literal> matches any alphanumeric
  52. character</para></listitem>
  53. <listitem><para><literal>[[:alpha:]]</literal> matches any alphabetical character</para></listitem>
  54. <listitem><para><literal>[[:blank:]]</literal> matches a space or horizontal tab</para></listitem>
  55. <listitem><para><literal>[[:cntrl:]]</literal> matches a control character</para></listitem>
  56. <listitem><para><literal>[[:digit:]]</literal> matches a decimal digit</para></listitem>
  57. <listitem><para><literal>[[:graph:]]</literal> matches a non-space, non-control character</para></listitem>
  58. <listitem><para><literal>[[:lower:]]</literal> matches a lowercase letter</para></listitem>
  59. <listitem><para><literal>[[:print:]]</literal> same as <literal>[[:graph:]]</literal>, but also space and tab</para></listitem>
  60. <listitem><para><literal>[[:punct:]]</literal> matches a punctuation character</para></listitem>
  61. <listitem><para><literal>[[:space:]]</literal> matches any whitespace character, including newlines</para></listitem>
  62. <listitem><para><literal>[[:upper:]]</literal> matches an uppercase letter</para></listitem>
  63. <listitem><para><literal>[[:xdigit:]]</literal> matches a valid hexadecimal digit</para></listitem>
  64. </itemizedlist>
  65. <bridgehead renderas="sect3">Subexpressions and Backreferences</bridgehead>
  66. <itemizedlist>
  67. <listitem><para><literal>(<replaceable>abc</replaceable>)</literal> matches
  68. whatever the expression
  69. <replaceable>abc</replaceable> would match, and saves it as a subexpression.
  70. Also used for grouping</para></listitem>
  71. <listitem><para><literal>(?:<replaceable>...</replaceable>)</literal> pure
  72. grouping operator, does not
  73. save contents</para></listitem>
  74. <listitem><para><literal>(?#<replaceable>...</replaceable>)</literal> embedded
  75. comment, ignored by engine</para></listitem>
  76. <listitem><para><literal>(?=<replaceable>...</replaceable>)</literal> positive
  77. lookahead; the regular expression will match if the text in the brackets
  78. matches, but that text will not be considered part of the match</para></listitem>
  79. <listitem><para><literal>(?!<replaceable>...</replaceable>)</literal> negative
  80. lookahead; the regular expression will match if the text in the brackets
  81. does not
  82. match, and that text will not be considered part of the match</para></listitem>
  83. <listitem><para><literal>\<replaceable>n</replaceable></literal> where 0 &lt;
  84. <replaceable>n</replaceable> &lt; 10,
  85. matches the same thing the <replaceable>n</replaceable>th
  86. subexpression matched. Can only be used in the search string</para></listitem>
  87. <listitem><para><literal>$<replaceable>n</replaceable></literal> where 0 &lt;
  88. <replaceable>n</replaceable> &lt; 10,
  89. substituted with the text matched by the <replaceable>n</replaceable>th
  90. subexpression. Can only be used in the replacement string</para></listitem>
  91. </itemizedlist>
  92. <bridgehead renderas="sect3">Branching (Alternation) Operator</bridgehead>
  93. <itemizedlist>
  94. <listitem><para><literal><replaceable>a</replaceable>|<replaceable>b</replaceable></literal>
  95. matches whatever the expression <replaceable>a</replaceable> would match, or whatever
  96. the expression <replaceable>b</replaceable> would match.</para></listitem>
  97. </itemizedlist>
  98. <bridgehead renderas="sect3">Repeating Operators</bridgehead>
  99. <para>
  100. These symbols operate on the previous atomic expression.
  101. </para>
  102. <itemizedlist>
  103. <listitem><para><literal>?</literal> matches the preceding expression or the
  104. null string</para></listitem>
  105. <listitem><para><literal>*</literal> matches the null string or any number of repetitions
  106. of the preceding expression</para></listitem>
  107. <listitem><para><literal>+</literal> matches one or more repetitions of the preceding
  108. expression</para></listitem>
  109. <listitem><para><literal>{<replaceable>m</replaceable>}</literal> matches exactly
  110. <replaceable>m</replaceable>
  111. repetitions of the one-character expression</para></listitem>
  112. <listitem><para><literal>{<replaceable>m</replaceable>,<replaceable>n</replaceable>}</literal>
  113. matches between
  114. <replaceable>m</replaceable> and <replaceable>n</replaceable> repetitions of the preceding
  115. expression, inclusive</para></listitem>
  116. <listitem><para><literal>{<replaceable>m</replaceable>,}</literal> matches
  117. <replaceable>m</replaceable> or more
  118. repetitions of the preceding expression</para></listitem>
  119. </itemizedlist>
  120. <bridgehead renderas="sect3">Stingy (Minimal) Matching</bridgehead>
  121. <para>
  122. If a repeating operator (above) is immediately followed by a
  123. <literal>?</literal>, the repeating operator will stop at the smallest
  124. number of repetitions that can complete the rest of the match.
  125. </para>
  126. </appendix>