📄 regexp.reference.html
字号:
<dd><span class="simpara">character with hex code hh</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\ddd</em></span> <dd><span class="simpara">character with octal code ddd, or backreference</span></dd> </dt> </dl> </p> <p class="para"> The precise effect of "<i>\cx</i>" is as follows: if "<i>x</i>" is a lower case letter, it is converted to upper case. Then bit 6 of the character (hex 40) is inverted. Thus "<i>\cz</i>" becomes hex 1A, but "<i>\c{</i>" becomes hex 3B, while "<i>\c;</i>" becomes hex 7B. </p> <p class="para"> After "<i>\x</i>", up to two hexadecimal digits are read (letters can be in upper or lower case). In <em class="emphasis">UTF-8 mode</em>, "<i>\x{...}</i>" is allowed, where the contents of the braces is a string of hexadecimal digits. It is interpreted as a UTF-8 character whose code number is the given hexadecimal number. The original hexadecimal escape sequence, <i>\xhh</i>, matches a two-byte UTF-8 character if the value is greater than 127. </p> <p class="para"> After "<i>\0</i>" up to two further octal digits are read. In both cases, if there are fewer than two digits, just those that are present are used. Thus the sequence "<i>\0\x\07</i>" specifies two binary zeros followed by a BEL character. Make sure you supply two digits after the initial zero if the character that follows is itself an octal digit. </p> <p class="para"> The handling of a backslash followed by a digit other than 0 is complicated. Outside a character class, PCRE reads it and any following digits as a decimal number. If the number is less than 10, or if there have been at least that many previous capturing left parentheses in the expression, the entire sequence is taken as a <em class="emphasis">back</em> <em class="emphasis">reference</em>. A description of how this works is given later, following the discussion of parenthesized subpatterns. </p> <p class="para"> Inside a character class, or if the decimal number is greater than 9 and there have not been that many capturing subpatterns, PCRE re-reads up to three octal digits following the backslash, and generates a single byte from the least significant 8 bits of the value. Any subsequent digits stand for themselves. For example: </p> <p class="para"> <dl> <dt> <span class="term"><em class="emphasis">\040</em></span> <dd><span class="simpara">is another way of writing a space</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\40</em></span> <dd> <span class="simpara"> is the same, provided there are fewer than 40 previous capturing subpatterns </span> </dd> </dt> <dt> <span class="term"><em class="emphasis">\7</em></span> <dd><span class="simpara">is always a back reference</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\11</em></span> <dd> <span class="simpara"> might be a back reference, or another way of writing a tab </span> </dd> </dt> <dt> <span class="term"><em class="emphasis">\011</em></span> <dd><span class="simpara">is always a tab</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\0113</em></span> <dd><span class="simpara">is a tab followed by the character "3"</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\113</em></span> <dd> <span class="simpara"> is the character with octal code 113 (since there can be no more than 99 back references) </span> </dd> </dt> <dt> <span class="term"><em class="emphasis">\377</em></span> <dd><span class="simpara">is a byte consisting entirely of 1 bits</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\81</em></span> <dd> <span class="simpara"> is either a back reference, or a binary zero followed by the two characters "8" and "1" </span> </dd> </dt> </dl> </p> <p class="para"> Note that octal values of 100 or greater must not be introduced by a leading zero, because no more than three octal digits are ever read. </p> <p class="para"> All the sequences that define a single byte value can be used both inside and outside character classes. In addition, inside a character class, the sequence "<i>\b</i>" is interpreted as the backspace character (hex 08). Outside a character class it has a different meaning (see below). </p> <p class="para"> The third use of backslash is for specifying generic character types: </p> <p class="para"> <dl> <dt> <span class="term"><em class="emphasis">\d</em></span> <dd><span class="simpara">any decimal digit</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\D</em></span> <dd><span class="simpara">any character that is not a decimal digit</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\h</em></span> <dd><span class="simpara">any horizontal whitespace character (since PHP 5.2.4)</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\H</em></span> <dd><span class="simpara">any character that is not a horizontal whitespace character (since PHP 5.2.4)</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\s</em></span> <dd><span class="simpara">any whitespace character</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\S</em></span> <dd><span class="simpara">any character that is not a whitespace character</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\v</em></span> <dd><span class="simpara">any vertical whitespace character (since PHP 5.2.4)</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\V</em></span> <dd><span class="simpara">any character that is not a vertical whitespace character (since PHP 5.2.4)</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\w</em></span> <dd><span class="simpara">any "word" character</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\W</em></span> <dd><span class="simpara">any "non-word" character</span></dd> </dt> </dl> </p> <p class="para"> Each pair of escape sequences partitions the complete set of characters into two disjoint sets. Any given character matches one, and only one, of each pair. </p> <p class="para"> A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "<i>word</i>". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by <i>\w</i>. </p> <p class="para"> These character type sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match. </p> <p class="para"> The fourth use of backslash is for certain simple assertions. An assertion specifies a condition that has to be met at a particular point in a match, without consuming any characters from the subject string. The use of subpatterns for more complicated assertions is described below. The backslashed assertions are </p> <p class="para"> <dl> <dt> <span class="term"><em class="emphasis">\b</em></span> <dd><span class="simpara">word boundary</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\B</em></span> <dd><span class="simpara">not a word boundary</span></dd> </dt> <dt> <span class="term"><em class="emphasis">\A</em></span> <dd><span class="simpara">start of subject (independent of multiline mode)</span></dd> </dt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -