NAME ¶
perlrecharclass - Perl Regular Expression Character Classes
perlrecharclass - Perl 正規表現文字クラス
説明¶
The top level documentation about Perl regular expressions is found in perlre.
Perl 正規表現に関する最上位文書は perlre です。
This manual page discusses the syntax and use of character classes in Perl regular expressions.
このマニュアルページは Perl 正規表現の文字クラスの文法と使用法について 議論します。
A character class is a way of denoting a set of characters in such a way that one character of the set is matched. It's important to remember that: matching a character class consumes exactly one character in the source string. (The source string is the string the regular expression is matched against.)
文字クラスは、集合の中の一文字がマッチングするというような方法で、 文字の集合を指定するための方法です。 次のことを覚えておくことは重要です: 文字集合はソース文字列の中から正確に 一文字だけを消費します。 (ソース文字列とは正規表現がマッチングしようとしている文字列です。)
There are three types of character classes in Perl regular expressions: the dot, backslash sequences, and the form enclosed in square brackets. Keep in mind, though, that often the term "character class" is used to mean just the bracketed form. Certainly, most Perl documentation does that.
Perl 正規表現には 3 種類の文字クラスがあります: ドット、 逆スラッシュシーケンス、大かっこで囲まれた形式です。 しかし、「文字クラス」という用語はしばしば大かっこ形式だけを意味するために 使われることに注意してください。 確かに、ほとんどの Perl 文書ではそうなっています。
ドット¶
The dot (or period), . is probably the most used, and certainly the most well-known character class. By default, a dot matches any character, except for the newline. That default can be changed to add matching the newline by using the single line modifier: either for the entire regular expression with the /s modifier, or locally with (?s). (The experimental \N backslash sequence, described below, matches any character except newline without regard to the single line modifier.)
ドット (またはピリオド) . はおそらくもっともよく使われ、そして確実に もっともよく知られている文字クラスです。 デフォルトでは、ドットは改行を除く任意の文字にマッチングします。 このデフォルトは 単一行 修飾子を使うことで改行にもマッチングするように 変更されます: 正規表現全体に対して /s 修飾子を使うか、ローカルには (?s) を使います。 (後述する実験的な \N 逆スラッシュシーケンスでは、単一行 修飾子に 関わりなく改行以外の任意の文字にマッチングします。)
Here are some examples:
以下は例です:
"a" =~ /./ # Match
"." =~ /./ # Match
"" =~ /./ # No match (dot has to match a character)
"\n" =~ /./ # No match (dot does not match a newline)
"\n" =~ /./s # Match (global 'single line' modifier)
"\n" =~ /(?s:.)/ # Match (local 'single line' modifier)
"ab" =~ /^.$/ # No match (dot matches one character)
"a" =~ /./ # マッチングする
"." =~ /./ # マッチングする
"" =~ /./ # マッチングしない (ドットは文字にマッチングする必要がある)
"\n" =~ /./ # マッチングしない (ドットは改行にはマッチングしない)
"\n" =~ /./s # マッチングする (グローバル「単一行」修飾子)
"\n" =~ /(?s:.)/ # マッチングする (ローカル「単一行」修飾子)
"ab" =~ /^.$/ # マッチングしない (ドットは一文字にマッチングする)
逆スラッシュシーケンス¶
A backslash sequence is a sequence of characters, the first one of which is a backslash. Perl ascribes special meaning to many such sequences, and some of these are character classes. That is, they match a single character each, provided that the character belongs to the specific set of characters defined by the sequence.
逆スラッシュシーケンスは、最初がバックスラッシュの文字並びです。 Perl はそのような並びの多くに特別な意味を持たせていて、 その一部は文字クラスです。 つまり、それらはそれぞれ並びによって定義されている特定の文字の集合に 帰属する一文字にマッチングします。
Here's a list of the backslash sequences that are character classes. They are discussed in more detail below. (For the backslash sequences that aren't character classes, see perlrebackslash.)
以下は文字クラスの逆スラッシュシーケンスの一覧です。 以下でさらに詳細に議論します。 (文字クラスではない逆スラッシュシーケンスについては、perlrebackslash を 参照してください。)
\d Match a decimal digit character.
\D Match a non-decimal-digit character.
\w Match a "word" character.
\W Match a non-"word" character.
\s Match a whitespace character.
\S Match a non-whitespace character.
\h Match a horizontal whitespace character.
\H Match a character that isn't horizontal whitespace.
\v Match a vertical whitespace character.
\V Match a character that isn't vertical whitespace.
\N Match a character that isn't a newline. Experimental.
\pP, \p{Prop} Match a character that has the given Unicode property.
\PP, \P{Prop} Match a character that doesn't have the Unicode property
\d 10 進数字にマッチング。
\D 非 10 進数字にマッチング。
\w 「単語」文字にマッチング。
\W 非「単語」文字にマッチング。
\s 空白文字にマッチング。
\S 非空白文字にマッチング。
\h 水平空白文字にマッチング。
\H 水平空白でない文字にマッチング。
\v 垂直空白文字にマッチング。
\V 垂直空白でない文字にマッチング。
\N 改行以外の文字にマッチング。実験的。
\pP, \p{Prop} 指定された Unicode 特性を持つ文字にマッチング。
\PP, \P{Prop} 指定された Unicode 特性を持たない文字にマッチング。
\N¶
\N is new in 5.12, and is experimental. It, like the dot, matches any character that is not a newline. The difference is that \N is not influenced by the single line regular expression modifier (see "The dot" above). Note that the form \N{...} may mean something completely different. When the {...} is a quantifier, it means to match a non-newline character that many times. For example, \N{3} means to match 3 non-newlines; \N{5,} means to match 5 or more non-newlines. But if {...} is not a legal quantifier, it is presumed to be a named character. See charnames for those. For example, none of \N{COLON}, \N{4F}, and \N{F4} contain legal quantifiers, so Perl will try to find characters whose names are respectively COLON, 4F, and F4.
\N は 5.12 の新機能で、実験的なものです。 これは、ドットのように、改行以外の任意の文字にマッチングします。 違いは、\N は 単一行 正規表現修飾子の影響を受けないことです (上述の "The dot" 参照)。 \N{...} 型式は何か全く違うものを意味するかも知れないことに 注意してください。 {...} が 量指定子 なら、これは指定された回数の 非改行文字にマッチングします。 例えば、\N{3} は三つの非改行にマッチングします; \N{5,} は五つ以上の非改行にマッチングします。 しかし、{...} が有効な量指定子でない場合、これは名前付き文字と 推定されます。 これについては charnames を参照してください。 例えば、\N{COLON}, \N{4F}, \N{F4} はどれも有効な 量指定子ではないので、Perl はそれぞれ COLON, 4F, F4 という名前の 文字を探そうとします。
数字¶
\d matches a single character considered to be a decimal digit. If the /a regular expression modifier is in effect, it matches [0-9]. Otherwise, it matches anything that is matched by \p{Digit}, which includes [0-9]. (An unlikely possible exception is that under locale matching rules, the current locale might not have [0-9] matched by \d, and/or might match other characters whose code point is less than 256. Such a locale definition would be in violation of the C language standard, but Perl doesn't currently assume anything in regard to this.)
\d は 10 進 数字 と考えられる単一の文字にマッチングします。 /a 正規表現修飾子が有効の場合、これは [0-9] にマッチングします。 さもなければ、これは [0-9] を含む、\p{Digit} にマッチングするものに マッチングします。 (ありそうもない例外はロケールマッチングの下で、現在のロケールが \d にマッチングする [0-9] がないか、 符号位置が 256 未満の他の文字にマッチングすることです。 このようなロケール定義は C 言語標準に違反していますが、 Perl は今のところこれに関して何も仮定しません。)
What this means is that unless the /a modifier is in effect \d not only matches the digits '0' - '9', but also Arabic, Devanagari, and digits from other languages. This may cause some confusion, and some security issues.
これが意味することは、/a 修飾子が有効でない限り、\d は数字 '0' - '9' だけでなく、アラビア文字、デバナーガリ文字、およびその他の言語の 数字もマッチングします。 これは混乱やセキュリティ問題を引き起こすことがあります。
Some digits that \d matches look like some of the [0-9] ones, but have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks very much like an ASCII DIGIT EIGHT (U+0038). An application that is expecting only the ASCII digits might be misled, or if the match is \d+, the matched string might contain a mixture of digits from different writing systems that look like they signify a number different than they actually do. "num()" in Unicode::UCD can be used to safely calculate the value, returning undef if the input string contains such a mixture.
\d にマッチングする数字には、[0-9] のように見えるけれども、 異なる値を持つものもあります。 例えば、BENGALI DIGIT FOUR (U+09EA) は ASCII DIGIT EIGHT (U+0038) と とてもよく似ています。 ASCII 数字のみを想定しているアプリケーションはミスリードされるかも知れず、 マッチングが \d+ の場合、 マッチングした文字列は、実際と異なる値を示しているように見える、 異なった書記体系からの数字が混ざったものかもしれません。 "num()" in Unicode::UCD は値を安全に計算するのに使えます; 入力文字列がこのような混合を含んでいる場合は undef を返します。
What \p{Digit} means (and hence \d except under the /a modifier) is \p{General_Category=Decimal_Number}, or synonymously, \p{General_Category=Digit}. Starting with Unicode version 4.1, this is the same set of characters matched by \p{Numeric_Type=Decimal}. But Unicode also has a different property with a similar name, \p{Numeric_Type=Digit}, which matches a completely different set of characters. These characters are things such as CIRCLED DIGIT ONE or subscripts, or are from writing systems that lack all ten digits.
\p{Digit} が意味するもの(つまり、/a 修飾子の下でない \d)は、 \p{General_Category=Decimal_Number}、または同義語として \p{General_Category=Digit} です。 Unicode バージョン 4.1 以降では、これは \p{Numeric_Type=Decimal} に マッチングする文字集合と同じです。 ただし、Unicode には、\p{Numeric_Type=Digit} という類似した名前を持つ 別の特性もあります; これは完全に異なる文字集合とマッチングします。 これらの文字は、CIRCLEED DIGIT ONE や添字のようなものであるか、 10 の数字すべてが揃っていない書記体系からのものです。
The design intent is for \d to exactly match the set of characters that can safely be used with "normal" big-endian positional decimal syntax, where, for example 123 means one 'hundred', plus two 'tens', plus three 'ones'. This positional notation does not necessarily apply to characters that match the other type of "digit", \p{Numeric_Type=Digit}, and so \d doesn't match them.
設計意図は、\d が「通常の」ビッグエンディアンの 位置 10 進構文 (例えば、123 は一つの「100」に二つの「10」と三つの「1」を 加えたものを意味する) で安全に使用できる文字集合と 正確にマッチングするようにすることです; この位置表記は、他のタイプの「digit」である \p{Numeric_Type=Digit} に マッチングする文字には必ずしも適用されないため、 \d はこれらの文字にマッチングしません。
The Tamil digits (U+0BE6 - U+0BEF) can also legally be used in old-style Tamil numbers in which they would appear no more than one in a row, separated by characters that mean "times 10", "times 100", etc. (See http://www.unicode.org/notes/tn21.)
タミル語の数字(U+0BE6-U+0BEF)は、古い様式のタミル語の 数字でも合法的に使用することができます; この数字は、「×10」や「×100」などを意味する文字で区切られて、 1 回に一度にしか現れません。 (http://www.unicode.org/notes/tn21を参照してください)。
Any character not matched by \d is matched by \D.
\d にマッチングしない任意の文字は \D にマッチングします。
単語文字¶
A \w matches a single alphanumeric character (an alphabetic character, or a decimal digit) or a connecting punctuation character, such as an underscore ("_"). It does not match a whole word. To match a whole word, use \w+. This isn't the same thing as matching an English word, but in the ASCII range it is the same as a string of Perl-identifier characters.
\w は単語全体ではなく、単一の英数字(つまり英字または数字)または 下線(_) のような接続句読点にマッチングします。 これは単語全体にはマッチングしません。 単語全体にマッチングするには、\w+ を使ってください。 これは英語の単語にマッチングするのと同じことではありませんが、 ASCII の範囲では、Perl の識別子文字の文字列と同じです。
- If the
/amodifier is in effect ... -
(
/a修飾子が有効なら ...)\wmatches the 63 characters [a-zA-Z0-9_].\wは 63 文字 [a-zA-Z0-9_] にマッチングします。 - otherwise ...
-
(さもなければ ...)
- For code points above 255 ...
-
(256 以上の符号位置では ...)
\wmatches the same as\p{Word}matches in this range. That is, it matches Thai letters, Greek letters, etc. This includes connector punctuation (like the underscore) which connect two words together, or diacritics, such as aCOMBINING TILDEand the modifier letters, which are generally used to add auxiliary markings to letters.\wはこの範囲で\p{Word}がマッチングするものと同じものに マッチングします。 つまり、タイ文字、ギリシャ文字などです。 これには(下線のような)二つの単語を繋ぐ接続句読点、COMBINING TILDEや一般的に文字に追加のマークを付けるために 使われる修飾字のようなダイアクリティカルマークが含まれます。 - For code points below 256 ...
-
(255 以下の符号位置では ...)
- if locale rules are in effect ...
-
(ロケール規則が有効なら ...)
\wmatches the platform's native underscore character plus whatever the locale considers to be alphanumeric.\wは、プラットフォームのネイティブな下線に加えてロケールが英数字と 考えるものにマッチングします。 - if Unicode rules are in effect or if on an EBCDIC platform ...
-
(Unicode 規則が有効か、EBCDIC プラットフォームなら ...)
\wmatches exactly what\p{Word}matches.\wは\p{Word}がマッチングするものと同じものにマッチングします。 - otherwise ...
-
(さもなければ ...)
\wmatches [a-zA-Z0-9_].\wは [a-zA-Z0-9_] にマッチングします。
Which rules apply are determined as described in "Which character set modifier is in effect?" in perlre.
どの規則を適用するかは "Which character set modifier is in effect?" in perlre で 記述されている方法で決定されます。
There are a number of security issues with the full Unicode list of word characters. See http://unicode.org/reports/tr36.
完全な Unicode の単語文字の一覧には多くのセキュリティ問題があります。 http://unicode.org/reports/tr36 を参照してください。
Also, for a somewhat finer-grained set of characters that are in programming language identifiers beyond the ASCII range, you may wish to instead use the more customized "Unicode Properties", \p{ID_Start}, \p{ID_Continue}, \p{XID_Start}, and \p{XID_Continue}. See http://unicode.org/reports/tr31.
また、ASCII の範囲を超えたプログラミング言語識別子のための より高精度の文字集合のためには、代わりによりカスタマイズされた Unicode 特性である \p{ID_Start}, \p{ID_Continue}, \p{XID_Start}, and \p{XID_Continue} を 使った方がよいでしょう。 http://unicode.org/reports/tr31 を参照してください。
Any character not matched by \w is matched by \W.
\w にマッチングしない任意の文字は \W にマッチングします。
空白¶
\s matches any single character considered whitespace.
\s は空白と考えられる単一の文字にマッチングします。
- If the
/amodifier is in effect ... -
(
/a修飾子が有効なら ...)\smatches the 5 characters [\t\n\f\r ]; that is, the horizontal tab, the newline, the form feed, the carriage return, and the space. (Note that it doesn't match the vertical tab,\cKon ASCII platforms.)\sは [\t\n\f\r ] の 5 文字にマッチングします; つまり、水平タブ、 改行、改頁、復帰、スペースです。 (ASCII プラットフォームでは\cKである垂直タブには マッチングしないことに注意してください。) - otherwise ...
-
(さもなければ ...)
- For code points above 255 ...
-
(256 以上の符号位置では ...)
\smatches exactly the code points above 255 shown with an "s" column in the table below.\sは、後述する表の "s" の列で示されている、 255 を超える符号位置に正確にマッチングします。 - For code points below 256 ...
-
(255 以下の符号位置では ...)
- if locale rules are in effect ...
-
(ロケール規則が有効なら ...)
\smatches whatever the locale considers to be whitespace. Note that this is likely to include the vertical space, unlike non-locale\smatching.\sはロケールが空白だと考えるものにマッチングします。 これは非ロケールの\sと異なりおそらく垂直スペースを含むことに 注意してください。 - if Unicode rules are in effect or if on an EBCDIC platform ...
-
\smatches exactly the characters shown with an "s" column in the table below.\sは正確に以下の表で "s" の列にある文字にマッチングします。 - otherwise ...
-
\smatches [\t\n\f\r ]. Note that this list doesn't include the non-breaking space.\sは [\t\n\f\r ] にマッチングします。 この一覧にはノーブレークスペースが含まれていないことに注意してください。
Which rules apply are determined as described in "Which character set modifier is in effect?" in perlre.
どの規則を適用するかは "Which character set modifier is in effect?" in perlre で 記述されている方法で決定されます。
Any character not matched by \s is matched by \S.
\s にマッチングしない任意の文字は \S にマッチングします。
\h matches any character considered horizontal whitespace; this includes the platform's space and tab characters and several others listed in the table below. \H matches any character not considered horizontal whitespace. They use the platform's native character set, and do not consider any locale that may otherwise be in use.
\h は水平空白と考えられる任意の文字にマッチングします; これは プラットフォームのスペースとタブ文字および以下の表に上げられている いくつかのその他の文字です。 \H は水平空白と考えられない文字にマッチングします。 これらはプラットフォームのネイティブな文字集合を使い、 他の場所では有効なロケールを考慮しません。
\v matches any character considered vertical whitespace; this includes the platform's carriage return and line feed characters (newline) plus several other characters, all listed in the table below. \V matches any character not considered vertical whitespace. They use the platform's native character set, and do not consider any locale that may otherwise be in use.
\v は垂直空白と考えられる任意の文字にマッチングします; これは プラットフォームの復帰と行送り(改行)文字に加えていくつかのその他の文字です; 全ては以下の表に挙げられています。 \V は垂直空白と考えられない任意の文字にマッチングします。 これらはプラットフォームのネイティブな文字集合を使い、 他の場所では有効なロケールを考慮しません。
\R matches anything that can be considered a newline under Unicode rules. It's not a character class, as it can match a multi-character sequence. Therefore, it cannot be used inside a bracketed character class; use \v instead (vertical whitespace). It uses the platform's native character set, and does not consider any locale that may otherwise be in use. Details are discussed in perlrebackslash.
\R は Unicode の規則で改行と考えられるものにマッチングします。 複数文字の並びにマッチングすることもあるので、これは 文字クラスではありません。 従って、大かっこ文字クラスの中では使えません; 代わりに \v (垂直空白) を 使ってください。 これらはプラットフォームのネイティブな文字集合を使い、 他の場所では有効なロケールを考慮しません。 詳細は perlrebackslash で議論しています。
Note that unlike \s (and \d and \w), \h and \v always match the same characters, without regard to other factors, such as the active locale or whether the source string is in UTF-8 format.
\s (および \d と \w) と違って、\h および \v は、現在の ロケールやソース文字列が UTF-8 形式かどうかといった他の要素に関わらず 同じ文字にマッチングします。
One might think that \s is equivalent to [\h\v]. This is not true. The difference is that the vertical tab ("\x0b") is not matched by \s; it is however considered vertical whitespace.
\s が [\h\v] と等価と考える人がいるかもしれません。 これは正しくありません。 違いは、垂直タブ ("\x0b") は \s にマッチングしないということです; 垂直空白と考えられます。
The following table is a complete listing of characters matched by \s, \h and \v as of Unicode 6.0.
以下の表は Unicode 6.0 現在で \s, \h, \v にマッチングする文字の 完全な一覧です。
The first column gives the Unicode code point of the character (in hex format), the second column gives the (Unicode) name. The third column indicates by which class(es) the character is matched (assuming no locale or EBCDIC code page is in effect that changes the \s matching).
最初の列は文字の Unicode 符号位置(16 進形式)、2 番目の列は (Unicode の) 名前です。 3 番目の列はどのクラスにマッチングするかを示しています (\s のマッチングを変更するようなロケールや EBCDIC コードページが 有効でないことを仮定しています)。
0x0009 CHARACTER TABULATION h s
0x000a LINE FEED (LF) vs
0x000b LINE TABULATION v
0x000c FORM FEED (FF) vs
0x000d CARRIAGE RETURN (CR) vs
0x0020 SPACE h s
0x0085 NEXT LINE (NEL) vs [1]
0x00a0 NO-BREAK SPACE h s [1]
0x1680 OGHAM SPACE MARK h s
0x180e MONGOLIAN VOWEL SEPARATOR h s
0x2000 EN QUAD h s
0x2001 EM QUAD h s
0x2002 EN SPACE h s
0x2003 EM SPACE h s
0x2004 THREE-PER-EM SPACE h s
0x2005 FOUR-PER-EM SPACE h s
0x2006 SIX-PER-EM SPACE h s
0x2007 FIGURE SPACE h s
0x2008 PUNCTUATION SPACE h s
0x2009 THIN SPACE h s
0x200a HAIR SPACE h s
0x2028 LINE SEPARATOR vs
0x2029 PARAGRAPH SEPARATOR vs
0x202f NARROW NO-BREAK SPACE h s
0x205f MEDIUM MATHEMATICAL SPACE h s
0x3000 IDEOGRAPHIC SPACE h s
- [1]
-
NEXT LINE and NO-BREAK SPACE may or may not match
\sdepending on the rules in effect. See the beginning of this section.NEXT LINE と NO-BREAK SPACE はどの規則が有効かによって
\sに マッチングしたりマッチングしなかったりします。 the beginning of this section を参照してください。
Unicode 特性¶
\pP and \p{Prop} are character classes to match characters that fit given Unicode properties. One letter property names can be used in the \pP form, with the property name following the \p, otherwise, braces are required. When using braces, there is a single form, which is just the property name enclosed in the braces, and a compound form which looks like \p{name=value}, which means to match if the property "name" for the character has that particular "value". For instance, a match for a number can be written as /\pN/ or as /\p{Number}/, or as /\p{Number=True}/. Lowercase letters are matched by the property Lowercase_Letter which has the short form Ll. They need the braces, so are written as /\p{Ll}/ or /\p{Lowercase_Letter}/, or /\p{General_Category=Lowercase_Letter}/ (the underscores are optional). /\pLl/ is valid, but means something different. It matches a two character string: a letter (Unicode property \pL), followed by a lowercase l.
\pP と \p{Prop} は指定された Unicode 特性に一致する文字に マッチングする文字クラスです。 一文字特性は \pP 形式で、\p に引き続いて特性名です; さもなければ 中かっこが必要です。 中かっこを使うとき、単に特性名を中かっこで囲んだ単一形式と、 \p{name=value} のような形で、文字の特性 "name" が特定の "value" を 持つものにマッチングすることになる複合形式があります。 例えば、数字にマッチングするものは /\pN/ または /\p{Number}/ または /\p{Number=True}/ と書けます。 小文字は LowercaseLetter 特性にマッチングします; これには Ll と言う短縮形式があります。 中かっこが必要なので、/\p{Ll}/ または /\p{Lowercase_Letter}/ または /\p{General_Category=Lowercase_Letter}/ と書きます(下線はオプションです)。 /\pLl/ も妥当ですが、違う意味になります。 これは 2 文字にマッチングします: 英字 (Unicode 特性 \pL)に引き続いて 小文字の l です。
If neither the /a modifier nor locale rules are in effect, the use of a Unicode property will force the regular expression into using Unicode rules.
/a 修飾子もロケール規則も有効でない場合、Unicode 特性を使うと 正規表現に Unicode 規則を使うように強制します。
Note that almost all properties are immune to case-insensitive matching. That is, adding a /i regular expression modifier does not change what they match. There are two sets that are affected. The first set is Uppercase_Letter, Lowercase_Letter, and Titlecase_Letter, all of which match Cased_Letter under /i matching. The second set is Uppercase, Lowercase, and Titlecase, all of which match Cased under /i matching. (The difference between these sets is that some things, such as Roman numerals, come in both upper and lower case, so they are Cased, but aren't considered to be letters, so they aren't Cased_Letters. They're actually Letter_Numbers.) This set also includes its subsets PosixUpper and PosixLower, both of which under /i match PosixAlpha.
ほとんど全ての特性は大文字小文字を無視したマッチングから免除されることに 注意してください。 つまり、/i 正規表現修飾子はこれらがマッチングするものに影響を 与えないということです。 影響を与える二つの集合があります。 一つ目の集合は Uppercase_Letter, Lowercase_Letter, Titlecase_Letter で、全て /i マッチングの下で Cased_Letter にマッチングします。 二つ目の集合は Uppercase, Lowercase, Titlecase で、全て/i マッチングの下で Cased にマッチングします。 (これらの集合の違いは、ローマ数字のような一部のものは、 大文字と小文字があるので Cased ですが、 文字とは扱われないので Cased_Letter ではありません。 これらは実際には Letter_Number です。) この集合はその部分集合である PosixUpper と PosixLower を含みます; これら両方は /i マッチングの下では PosixAlpha にマッチングします。
For more details on Unicode properties, see "Unicode Character Properties" in perlunicode; for a complete list of possible properties, see "Properties accessible through \p{} and \P{}" in perluniprops, which notes all forms that have /i differences. It is also possible to define your own properties. This is discussed in "User-Defined Character Properties" in perlunicode.
Unicode 特性に関するさらなる詳細については、 "Unicode Character Properties" in perlunicode を参照してください; 特性の完全な 一覧については、/i に違いのある全ての形式について記されている "Properties accessible through \p{} and \P{}" in perluniprops を参照して ください。 独自の特性を定義することも可能です。 これは "User-Defined Character Properties" in perlunicode で 議論されています。
Unicode properties are defined (surprise!) only on Unicode code points. A warning is raised and all matches fail on non-Unicode code points (those above the legal Unicode maximum of 0x10FFFF). This can be somewhat surprising,
Unicode 特性は (驚くべきことに!) Unicode 符号位置に対してのみ 定義されています。 非 Unicode 符号位置 (正当な Unicode の上限の 0x10FFFF を超えるもの) への マッチングの失敗は警告が発生します。 これは驚かされるものかもしれません。
chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails.
chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Also fails!
Even though these two matches might be thought of as complements, they are so only on Unicode code points.
これら二つのマッチングは補集合と考えるかもしれませんが、 これらは Unicode 符号位置だけです。
例¶
"a" =~ /\w/ # Match, "a" is a 'word' character.
"7" =~ /\w/ # Match, "7" is a 'word' character as well.
"a" =~ /\d/ # No match, "a" isn't a digit.
"7" =~ /\d/ # Match, "7" is a digit.
" " =~ /\s/ # Match, a space is whitespace.
"a" =~ /\D/ # Match, "a" is a non-digit.
"7" =~ /\D/ # No match, "7" is not a non-digit.
" " =~ /\S/ # No match, a space is not non-whitespace.
"a" =~ /\w/ # マッチング; "a" は「単語」文字。
"7" =~ /\w/ # マッチング; "7" も「単語」文字。
"a" =~ /\d/ # マッチングしない; "a" は数字ではない。
"7" =~ /\d/ # マッチング; "7" は数字。
" " =~ /\s/ # マッチング; スペースは空白。
"a" =~ /\D/ # マッチング; "a" は非数字。
"7" =~ /\D/ # マッチングしない; "7" は非数字ではない。
" " =~ /\S/ # マッチングしない; スペースは非空白ではない。
" " =~ /\h/ # Match, space is horizontal whitespace.
" " =~ /\v/ # No match, space is not vertical whitespace.
"\r" =~ /\v/ # Match, a return is vertical whitespace.
" " =~ /\h/ # マッチング; スペースは水平空白。
" " =~ /\v/ # マッチングしない; スペースは垂直空白ではない。
"\r" =~ /\v/ # マッチング; 復帰は垂直空白。
"a" =~ /\pL/ # Match, "a" is a letter.
"a" =~ /\p{Lu}/ # No match, /\p{Lu}/ matches upper case letters.