⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual_regexp.html

📁 这是一部完整的MYSQL中文参考手册,里面详尽的介绍了MYSQL的使用方法.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0073)manual_Regexp.html -->
<html>

<head>
<title>MySQL Reference Manual for version 3.23.7-alpha. - H Description of MySQL regular 
expression syntax</title>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<!-- This HTML file has been created by texi2html 1.52 (hacked by david@detron.se)
     from /dr1/my/masters/mysql-3.23/Docs/manual.texi on 9 December 1999 -->
<meta content="Microsoft FrontPage 3.0" name="GENERATOR">
</head>

<body bgColor="#ffffff" link="#101090" text="#000000" vLink="#7030b0">

<p>Go to the <a href="manual_Introduction.html">first</a>, <a href="manual_Porting.html">previous</a>, 
<a href="manual_Unireg.html">next</a>, <a href="manual_Concept_Index.html">last</a> 
section, <a href="manual_toc.html">table of contents</a>. </p>

<hr>

<h1><a href="manual_toc.html#Regexp" name="Regexp">H Description of MySQL regular 
expression syntax</a></h1>

<p>A regular expression (regex) is a powerful way of specifying a complex search. </p>

<p><strong>MySQL</strong> uses regular Henry Spencer's inplementation of regular 
expressions. And that is aimed to conform to POSIX 1003.2. <strong>MySQL</strong> uses the 
extended version. </p>

<p>This is a simplistic reference that skips the details. To get more exact information, 
see Henry Spencer's <code>regex(7)</code> manual page that is included in the source 
distribution. See section <a href="manual_Credits.html#Credits">C Contributors to MySQL</a>. 
</p>

<p>A regular expression describes a set of strings. The simplest regexp is one that has no 
special characters in it. For example, the regexp <code>hello</code> matches <code>hello</code> 
and nothing else. </p>

<p>Nontrivial regular expressions use certain special constructs so that they can match 
more than one string. For example, the regexp <code>hello|word</code> matches either the 
string <code>hello</code> or the string <code>word</code>. </p>

<p>As a more complex example, the regexp <code>B[an]*s</code> matches any of the strings <code>Bananas</code>, 
<code>Baaaaas</code>, <code>Bs</code> and any other string starting with a <code>B</code>, 
ending with an <code>s</code>, and containing any number of <code>a</code> or <code>n</code> 
characters in between. </p>

<p>A regular expression may use any of the following special characters/constructs: 

<dl compact>
  <dt><code>^</code> </dt>
  <dd>Match the beginning of a string. <pre>mysql&gt; select &quot;fo\nfo&quot; REGEXP &quot;^fo$&quot;;           -&gt; 0
mysql&gt; select &quot;fofo&quot; REGEXP &quot;^fo&quot;;              -&gt; 1
</pre>
  </dd>
  <dt><code>$</code> </dt>
  <dd>Match the end of a string. <pre>mysql&gt; select &quot;fo\no&quot; REGEXP &quot;^fo\no$&quot;;         -&gt; 1
mysql&gt; select &quot;fo\no&quot; REGEXP &quot;^fo$&quot;;            -&gt; 0
</pre>
  </dd>
  <dt><code>.</code> </dt>
  <dd>Match any character (including newline). <pre>mysql&gt; select &quot;fofo&quot; REGEXP &quot;^f.*&quot;;             -&gt; 1
mysql&gt; select &quot;fo\nfo&quot; REGEXP &quot;^f.*&quot;;           -&gt; 1
</pre>
  </dd>
  <dt><code>a*</code> </dt>
  <dd>Match any sequence of zero or more <code>a</code> characters. <pre>mysql&gt; select &quot;Ban&quot; REGEXP &quot;^Ba*n&quot;;             -&gt; 1
mysql&gt; select &quot;Baaan&quot; REGEXP &quot;^Ba*n&quot;;           -&gt; 1
mysql&gt; select &quot;Bn&quot; REGEXP &quot;^Ba*n&quot;;              -&gt; 1
</pre>
  </dd>
  <dt><code>a+</code> </dt>
  <dd>Match any sequence of one or more <code>a</code> characters. <pre>mysql&gt; select &quot;Ban&quot; REGEXP &quot;^Ba+n&quot;;             -&gt; 1
mysql&gt; select &quot;Bn&quot; REGEXP &quot;^Ba+n&quot;;              -&gt; 0
</pre>
  </dd>
  <dt><code>a?</code> </dt>
  <dd>Match either zero or one <code>a</code> character. <pre>mysql&gt; select &quot;Bn&quot; REGEXP &quot;^Ba?n&quot;;              -&gt; 1
mysql&gt; select &quot;Ban&quot; REGEXP &quot;^Ba?n&quot;;             -&gt; 1
mysql&gt; select &quot;Baan&quot; REGEXP &quot;^Ba?n&quot;;            -&gt; 0
</pre>
  </dd>
  <dt><code>de|abc</code> </dt>
  <dd>Match either of the sequences <code>de</code> or <code>abc</code>. <pre>mysql&gt; select &quot;pi&quot; REGEXP &quot;pi|apa&quot;;             -&gt; 1
mysql&gt; select &quot;axe&quot; REGEXP &quot;pi|apa&quot;;            -&gt; 0
mysql&gt; select &quot;apa&quot; REGEXP &quot;pi|apa&quot;;            -&gt; 1
mysql&gt; select &quot;apa&quot; REGEXP &quot;^(pi|apa)$&quot;;        -&gt; 1
mysql&gt; select &quot;pi&quot; REGEXP &quot;^(pi|apa)$&quot;;         -&gt; 1
mysql&gt; select &quot;pix&quot; REGEXP &quot;^(pi|apa)$&quot;;        -&gt; 0
</pre>
  </dd>
  <dt><code>(abc)*</code> </dt>
  <dd>Match zero or more instances of the sequence <code>abc</code>. <pre>mysql&gt; select &quot;pi&quot; REGEXP &quot;^(pi)*$&quot;;            -&gt; 1
mysql&gt; select &quot;pip&quot; REGEXP &quot;^(pi)*$&quot;;           -&gt; 0
mysql&gt; select &quot;pipi&quot; REGEXP &quot;^(pi)*$&quot;;          -&gt; 1
</pre>
  </dd>
  <dt><code>{1}</code> </dt>
  <dd> </dd>
  <dt><code>{2,3}</code> </dt>
  <dd>The is a more general way of writing regexps that match many occurrences of the previous 
    atom. <dl compact>
      <dt><code>a*</code> </dt>
      <dd>Can be written as <code>a{0,}</code>. </dd>
      <dt><code>a+</code> </dt>
      <dd>Can be written as <code>a{1,}</code>. </dd>
      <dt><code>a?</code> </dt>
      <dd>Can be written as <code>a{0,1}</code>. </dd>
    </dl>
    <p>To be more precise, an atom followed by a bound containing one integer <code>i</code> 
    and no comma matches a sequence of exactly <code>i</code> matches of the atom. An atom 
    followed by a bound containing one integer <code>i</code> and a comma matches a sequence 
    of <code>i</code> or more matches of the atom. An atom followed by a bound containing two 
    integers <code>i</code> and <code>j</code> matches a sequence of <code>i</code> through <code>j</code> 
    (inclusive) matches of the atom. Both arguments must <code>0 &gt;= value &lt;= RE_DUP_MAX 
    (default 255)</code>. If there are two arguments, the second must be greater than or equal 
    to the first. </p>
  </dd>
  <dt><code>[a-dX]</code> </dt>
  <dd> </dd>
  <dt><code>[^a-dX]</code> </dt>
  <dd>Matches any character which is (or is not, if ^ is used) either <code>a</code>, <code>b</code>, 
    <code>c</code>, <code>d</code> or <code>X</code>. To include a literal <code>]</code> 
    character, it must immediately follow the opening bracket <code>[</code>. To include a 
    literal <code>-</code> character, it must be written first or last. So <code>[0-9]</code> 
    matches any decimal digit. Any character that does not have a defined meaning inside a <code>[]</code> 
    pair has no special meaning and matches only itself. <pre>mysql&gt; select &quot;aXbc&quot; REGEXP &quot;[a-dXYZ]&quot;;         -&gt; 1
mysql&gt; select &quot;aXbc&quot; REGEXP &quot;^[a-dXYZ]$&quot;;       -&gt; 0
mysql&gt; select &quot;aXbc&quot; REGEXP &quot;^[a-dXYZ]+$&quot;;      -&gt; 1
mysql&gt; select &quot;aXbc&quot; REGEXP &quot;^[^a-dXYZ]+$&quot;;     -&gt; 0
mysql&gt; select &quot;gheis&quot; REGEXP &quot;^[^a-dXYZ]+$&quot;;    -&gt; 1
mysql&gt; select &quot;gheisa&quot; REGEXP &quot;^[^a-dXYZ]+$&quot;;   -&gt; 0
</pre>
  </dd>
  <dt><code>[[.characters.]]</code> </dt>
  <dd>The sequence of characters of that collating element. The sequence is a single element 
    of the bracket expression's list. A bracket expression containing a multi-character 
    collating element can thus match more than one character, e.g., if the collating sequence 
    includes a <code>ch</code> collating element, then the regular expression <code>[[.ch.]]*c</code> 
    matches the first five characters of <code>chchcc</code>. </dd>
  <dt><code>[=character_class=]</code> </dt>
  <dd>An equivalence class, standing for the sequences of characters of all collating elements 
    equivalent to that one, including itself. For example, if <code>o</code> and <code>(+)</code> 
    are the members of an equivalence class, then <code>[[=o=]]</code>, <code>[[=(+)=]]</code>, 
    and <code>[o(+)]</code> are all synonymous. An equivalence class may not be an endpoint of 
    a range. </dd>
  <dt><code>[:character_class:]</code> </dt>
  <dd>Within a bracket expression, the name of a character class enclosed in <code>[:</code> 
    and <code>:]</code> stands for the list of all characters belonging to that class. 
    Standard character class names are: <table border="1" width="100%" NOSAVE>
<TBODY>
      <tr>
        <td>alnum </td>
        <td>digit </td>
        <td>punct </td>
      </tr>
      <tr>
        <td>alpha </td>
        <td>graph </td>
        <td>space </td>
      </tr>
      <tr>
        <td>blank </td>
        <td>lower </td>
        <td>upper </td>
      </tr>
      <tr>
        <td>cntrl </td>
        <td>print </td>
        <td>xdigit </td>
      </tr>
</TBODY>
    </table>
    <p>These stand for the character classes defined in the <code>ctype(3)</code> manual page. 
    A locale may provide others. A character class may not be used as an endpoint of a range. </p>
    <pre>mysql&gt; select &quot;justalnums&quot; REGEXP &quot;[[:alnum:]]+&quot;;       -&gt; 1
mysql&gt; select &quot;!!&quot; REGEXP &quot;[[:alnum:]]+&quot;;               -&gt; 0
</pre>
  </dd>
  <dt><code>[[:&lt;:]]</code> </dt>
  <dd> </dd>
  <dt><code>[[:&gt;:]]</code> </dt>
  <dd>These match the null string at the beginning and end of a word respectively. A word is 
    defined as a sequence of word characters which is neither preceded nor followed by word 
    characters. A word character is an alnum character (as defined by <code>ctype(3)</code>) 
    or an underscore (<code>_</code>). <pre>mysql&gt; select &quot;a word a&quot; REGEXP &quot;[[:&lt;:]]word[[:&gt;:]]&quot;;      -&gt; 1
mysql&gt; select &quot;a xword a&quot; REGEXP &quot;[[:&lt;:]]word[[:&gt;:]]&quot;;     -&gt; 0
</pre>
  </dd>
</dl>

<pre>mysql&gt; select &quot;weeknights&quot; REGEXP &quot;^(wee|week)(knights|nights)$&quot;; -&gt; 1
</pre>

<hr>

<p>Go to the <a href="manual_Introduction.html">first</a>, <a href="manual_Porting.html">previous</a>, 
<a href="manual_Unireg.html">next</a>, <a href="manual_Concept_Index.html">last</a> 
section, <a href="manual_toc.html">table of contents</a>. </p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -