perlunicode.html

来自「perl教程」· HTML 代码 · 共 1,163 行 · 第 1/5 页

HTML
1,163
字号
Unicode properties database.  <code>\w</code> can be used to match a Japanese
ideograph, for instance.</p>
<p>(However, and as a limitation of the current implementation, using
<code>\w</code> or <code>\W</code> <em>inside</em> a <code>[...]</code> character class will still match
with byte semantics.)</p>
</li>
<li>
<p>Named Unicode properties, scripts, and block ranges may be used like
character classes via the <code>\p{}</code> &quot;matches property&quot; construct and
the  <code>\P{}</code> negation, &quot;doesn't match property&quot;.</p>
<p>For instance, <code>\p{Lu}</code> matches any character with the Unicode &quot;Lu&quot;
(Letter, uppercase) property, while <code>\p{M}</code> matches any character
with an &quot;M&quot; (mark--accents and such) property.  Brackets are not
required for single letter properties, so <code>\p{M}</code> is equivalent to
<code>\pM</code>. Many predefined properties are available, such as
<code>\p{Mirrored}</code> and <code>\p{Tibetan}</code>.</p>
<p>The official Unicode script and block names have spaces and dashes as
separators, but for convenience you can use dashes, spaces, or
underbars, and case is unimportant. It is recommended, however, that
for consistency you use the following naming: the official Unicode
script, property, or block name (see below for the additional rules
that apply to block names) with whitespace and dashes removed, and the
words &quot;uppercase-first-lowercase-rest&quot;. <code>Latin-1 Supplement</code> thus
becomes <code>Latin1Supplement</code>.</p>
<p>You can also use negation in both <code>\p{}</code> and <code>\P{}</code> by introducing a caret
(^) between the first brace and the property name: <code>\p{^Tamil}</code> is
equal to <code>\P{Tamil}</code>.</p>
<p><strong>NOTE: the properties, scripts, and blocks listed here are as of
Unicode 3.2.0, March 2002, or Perl 5.8.0, July 2002.  Unicode 4.0.0
came out in April 2003, and Perl 5.8.1 in September 2003.</strong></p>
<p>Here are the basic Unicode General Category properties, followed by their
long form.  You can use either; <code>\p{Lu}</code> and <code>\p{UppercaseLetter}</code>,
for instance, are identical.</p>
<pre>
    Short       Long</pre>
<pre>
    L           Letter
    LC          CasedLetter
    Lu          UppercaseLetter
    Ll          LowercaseLetter
    Lt          TitlecaseLetter
    Lm          ModifierLetter
    Lo          OtherLetter</pre>
<pre>
    M           Mark
    Mn          NonspacingMark
    Mc          SpacingMark
    Me          EnclosingMark</pre>
<pre>
    N           Number
    Nd          DecimalNumber
    Nl          LetterNumber
    No          OtherNumber</pre>
<pre>
    P           Punctuation
    Pc          ConnectorPunctuation
    Pd          DashPunctuation
    Ps          OpenPunctuation
    Pe          ClosePunctuation
    Pi          InitialPunctuation
                (may behave like Ps or Pe depending on usage)
    Pf          FinalPunctuation
                (may behave like Ps or Pe depending on usage)
    Po          OtherPunctuation</pre>
<pre>
    S           Symbol
    Sm          MathSymbol
    Sc          CurrencySymbol
    Sk          ModifierSymbol
    So          OtherSymbol</pre>
<pre>
    Z           Separator
    Zs          SpaceSeparator
    Zl          LineSeparator
    Zp          ParagraphSeparator</pre>
<pre>
    C           Other
    Cc          Control
    Cf          Format
    Cs          Surrogate   (not usable)
    Co          PrivateUse
    Cn          Unassigned</pre>
<p>Single-letter properties match all characters in any of the
two-letter sub-properties starting with the same letter.
<code>LC</code> and <code>L&amp;</code> are special cases, which are aliases for the set of
<code>Ll</code>, <code>Lu</code>, and <code>Lt</code>.</p>
<p>Because Perl hides the need for the user to understand the internal
representation of Unicode characters, there is no need to implement
the somewhat messy concept of surrogates. <code>Cs</code> is therefore not
supported.</p>
<p>Because scripts differ in their directionality--Hebrew is
written right to left, for example--Unicode supplies these properties in
the BidiClass class:</p>
<pre>
    Property    Meaning</pre>
<pre>
    L           Left-to-Right
    LRE         Left-to-Right Embedding
    LRO         Left-to-Right Override
    R           Right-to-Left
    AL          Right-to-Left Arabic
    RLE         Right-to-Left Embedding
    RLO         Right-to-Left Override
    PDF         Pop Directional Format
    EN          European Number
    ES          European Number Separator
    ET          European Number Terminator
    AN          Arabic Number
    CS          Common Number Separator
    NSM         Non-Spacing Mark
    BN          Boundary Neutral
    B           Paragraph Separator
    S           Segment Separator
    WS          Whitespace
    ON          Other Neutrals</pre>
<p>For example, <code>\p{BidiClass:R}</code> matches characters that are normally
written right to left.</p>
</li>
</ul>
<p>
</p>
<h2><a name="scripts">Scripts</a></h2>
<p>The script names which can be used by <code>\p{...}</code> and <code>\P{...}</code>,
such as in <code>\p{Latin}</code> or <code>\p{Cyrillic}</code>, are as follows:</p>
<pre>
    Arabic
    Armenian
    Bengali
    Bopomofo
    Buhid
    CanadianAboriginal
    Cherokee
    Cyrillic
    Deseret
    Devanagari
    Ethiopic
    Georgian
    Gothic
    Greek
    Gujarati
    Gurmukhi
    Han
    Hangul
    Hanunoo
    Hebrew
    Hiragana
    Inherited
    Kannada
    Katakana
    Khmer
    Lao
    Latin
    Malayalam
    Mongolian
    Myanmar
    Ogham
    OldItalic
    Oriya
    Runic
    Sinhala
    Syriac
    Tagalog
    Tagbanwa
    Tamil
    Telugu
    Thaana
    Thai
    Tibetan
    Yi</pre>
<p>Extended property classes can supplement the basic
properties, defined by the <em>PropList</em> Unicode database:</p>
<pre>
    ASCIIHexDigit
    BidiControl
    Dash
    Deprecated
    Diacritic
    Extender
    GraphemeLink
    HexDigit
    Hyphen
    Ideographic
    IDSBinaryOperator
    IDSTrinaryOperator
    JoinControl
    LogicalOrderException
    NoncharacterCodePoint
    OtherAlphabetic
    OtherDefaultIgnorableCodePoint
    OtherGraphemeExtend
    OtherLowercase
    OtherMath
    OtherUppercase
    QuotationMark
    Radical
    SoftDotted
    TerminalPunctuation
    UnifiedIdeograph
    WhiteSpace</pre>
<p>and there are further derived properties:</p>
<pre>
    Alphabetic      Lu + Ll + Lt + Lm + Lo + OtherAlphabetic
    Lowercase       Ll + OtherLowercase
    Uppercase       Lu + OtherUppercase
    Math            Sm + OtherMath</pre>
<pre>
    ID_Start        Lu + Ll + Lt + Lm + Lo + Nl
    ID_Continue     ID_Start + Mn + Mc + Nd + Pc</pre>
<pre>
    <span class="variable">Any</span>             <span class="variable">Any</span> <span class="variable">character</span>
    <span class="variable">Assigned</span>        <span class="variable">Any</span> <span class="variable">non</span><span class="operator">-</span><span class="variable">Cn</span> <span class="variable">character</span> <span class="operator">(</span><span class="variable">i</span><span class="operator">.</span><span class="variable">e</span><span class="operator">.</span> <span class="variable">synonym</span> <span class="keyword">for</span> <span class="operator">\</span><span class="variable">P</span><span class="operator">{</span><span class="variable">Cn</span><span class="operator">})</span>
    <span class="variable">Unassigned</span>      <span class="variable">Synonym</span> <span class="keyword">for</span> <span class="operator">\</span><span class="variable">p</span><span class="operator">{</span><span class="variable">Cn</span><span class="operator">}</span>
    <span class="variable">Common</span>          <span class="variable">Any</span> <span class="variable">character</span> <span class="operator">(</span><span class="keyword">or</span> <span class="variable">unassigned</span> <span class="variable">code</span> <span class="variable">point</span><span class="operator">)</span>
                    <span class="keyword">not</span> <span class="variable">explicitly</span> <span class="variable">assigned</span> <span class="variable">to</span> <span class="variable">a</span> <span class="variable">script</span>
</pre>
<p>For backward compatibility (with Perl 5.6), all properties mentioned
so far may have <code>Is</code> prepended to their name, so <code>\P{IsLu}</code>, for
example, is equal to <code>\P{Lu}</code>.</p>
<p>
</p>
<h2><a name="blocks">Blocks</a></h2>
<p>In addition to <strong>scripts</strong>, Unicode also defines <strong>blocks</strong> of
characters.  The difference between scripts and blocks is that the
concept of scripts is closer to natural languages, while the concept
of blocks is more of an artificial grouping based on groups of 256
Unicode characters. For example, the <code>Latin</code> script contains letters
from many blocks but does not contain all the characters from those
blocks. It does not, for example, contain digits, because digits are
shared across many scripts. Digits and similar groups, like
punctuation, are in a category called <code>Common</code>.</p>
<p>For more about scripts, see the UTR #24:</p>
<pre>
   <a href="http://www.unicode.org/unicode/reports/tr24/">http://www.unicode.org/unicode/reports/tr24/</a></pre>

⌨️ 快捷键说明

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