=encoding euc-jp =head1 NAME =begin original perlreref - Perl Regular Expressions Reference =end original perlreref - Perl の正規表現のリファレンス =head1 DESCRIPTION =begin original This is a quick reference to Perl's regular expressions. For full information see L and L, as well as the L section in this document. =end original 本ドキュメントは、Perl の正規表現のクイックリファレンスです。 完全な情報は、L と L、また、本ドキュメントの L セクションを参照してください。 =head2 OPERATORS (演算子) =begin original C<=~> determines to which variable the regex is applied. In its absence, $_ is used. =end original C<=~> は正規表現が適用される変数を決定します。 省略された場合には、$_ が使われます。 $var =~ /foo/; =begin original C determines to which variable the regex is applied, and negates the result of the match; it returns false if the match succeeds, and true if it fails. =end original C は正規表現が適用される変数を決定し、マッチの結果を反転します; マッチが成功すれば偽を返し、失敗すれば真を返します。 $var !~ /foo/; =begin original C searches a string for a pattern match, applying the given options. =end original C パターンマッチのために文字列を検索し、 与えられたオプションを適用します。 =begin original m Multiline mode - ^ and $ match internal lines s match as a Single line - . matches \n i case-Insensitive x eXtended legibility - free whitespace and comments p Preserve a copy of the matched string - ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be defined. o compile pattern Once g Global - all occurrences c don't reset pos on failed matches when using /g a restrict \d, \s, \w and [:posix:] to match ASCII only aa (two a's) also /i matches exclude ASCII/non-ASCII l match according to current locale u match according to Unicode rules d match according to native rules unless something indicates Unicode =end original m 複数行モード - ^ と $ が内部的な行にマッチします s 単行としてマッチ - . が \n にマッチします i 大小文字の違いを無視します x 読みやすさの拡張 - 空白やコメントを自由に置けます p マッチした文字列のコピーを保存する - ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} が定義されます。 o パターンを一度だけコンパイルします g グローバル - マッチするものすべて c /g を使っているときにマッチに失敗しても pos をリセットしません a \d, \s, \w, [:posix:] で ASCII のみにマッチングするように制限 aa (二つの a) また /i のマッチングは ASCII/非-ASCII を除外 l 現在のロケールに従ってマッチング u Unicode のルールに従ってマッチング d Unicode を示すものがない限りネイティブなルールに従ってマッチング =begin original If 'pattern' is an empty string, the last I matched regex is used. Delimiters other than '/' may be used for both this operator and the following ones. The leading C can be omitted if the delimiter is '/'. =end original 'pattern' が空文字列なら、最後にマッチングに I<成功した> 正規表現が使われます。 この演算子とそれに続くものの両方で、'/' 以外のデリミタも使えます。 デリミタが '/' の場合は C は省略できます。 =begin original C lets you store a regex in a variable, or pass one around. Modifiers as for C, and are stored within the regex. =end original C は、正規表現を変数に入れるか、順に回せるように します。 C と同じ修飾子が使えて、正規表現に保管されます。 =begin original C substitutes matches of 'pattern' with 'replacement'. Modifiers as for C, with two additions: =end original C は、'pattern' でマッチしたものを 'replacement' で置き換えます。 C と同じ修飾子が使えて、さらに二つ追加されます: =begin original e Evaluate 'replacement' as an expression r Return substitution and leave the original string untouched. =end original e 'replacement' を式として評価します r 置換した結果を返し、元の文字列は変更しません。 =begin original 'e' may be specified multiple times. 'replacement' is interpreted as a double quoted string unless a single-quote (C<'>) is the delimiter. =end original 'e' は複数回指定できます。 'replacement' は、デリミタとしてシングルクォート (C<'>) が使われた場合を 除いて、ダブルクォートされた文字列として解釈されます。 =begin original C is like C but matches only once. No alternate delimiters can be used. Must be reset with reset(). =end original C は C に似ていますが、一度だけマッチします。 デリミタは変更できません。 reset() でリセットしなければなりません。 =head2 SYNTAX =begin original \ Escapes the character immediately following it . Matches any single character except a newline (unless /s is used) ^ Matches at the beginning of the string (or line, if /m is used) $ Matches at the end of the string (or line, if /m is used) * Matches the preceding element 0 or more times + Matches the preceding element 1 or more times ? Matches the preceding element 0 or 1 times {...} Specifies a range of occurrences for the element preceding it [...] Matches any one of the characters contained within the brackets (...) Groups subexpressions for capturing to $1, $2... (?:...) Groups subexpressions without capturing (cluster) | Matches either the subexpression preceding or following it \g1 or \g{1}, \g2 ... Matches the text from the Nth group \1, \2, \3 ... Matches the text from the Nth group \g-1 or \g{-1}, \g-2 ... Matches the text from the Nth previous group \g{name} Named backreference \k Named backreference \k'name' Named backreference (?P=name) Named backreference (python syntax) =end original \ 直後の文字をエスケープします . 改行を除く任意の一文字にマッチします (/s が使われていない場合) ^ 文字列(/m が使われている場合は行)の先頭にマッチします $ 文字列(/m が使われている場合は行)の末尾にマッチします * 先行する要素のゼロ回以上の繰り返しにマッチします + 先行する要素の一回以上の繰り返しにマッチします ? 先行する要素のゼロ回または一回の出現にマッチします {...} 先行する要素の繰り返しの範囲を指定します [...] ブラケットの内側にある文字のいずれかにマッチします (...) $1, $2... のために部分正規表現をグループ化して捕捉します (?:...) 部分正規表現を捕捉することなくグループ化します (クラスター) | 左右いずれかにある部分正規表現にマッチします \g1 or \g{1}, \g2 ... N 番目のグループのテキストにマッチします \1, \2, \3 ... N 番目のグループのテキストにマッチします \g-1 or \g{-1}, \g-2 ... N 個前のグループのテキストにマッチします \g{name} 名前つき後方参照 \k 名前つき後方参照 \k'name' 名前つき後方参照 (?P=name) 名前つき後方参照 (python の文法) =head2 ESCAPE SEQUENCES (エスケープシーケンス) =begin original These work as in normal strings. =end original これらは通常の文字列として働きます。 =begin original \a Alarm (beep) \e Escape \f Formfeed \n Newline \r Carriage return \t Tab \037 Char whose ordinal is the 3 octal digits, max \777 \o{2307} Char whose ordinal is the octal number, unrestricted \x7f Char whose ordinal is the 2 hex digits, max \xFF \x{263a} Char whose ordinal is the hex number, unrestricted \cx Control-x \N{name} A named Unicode character or character sequence \N{U+263D} A Unicode character by hex ordinal =end original \a アラーム (ビープ) \e エスケープ \f 改ページ \n 改行 \r キャリッジリターン \t タブ \037 番号が 3 桁の 8 進数である文字、最大 \777 \o{2307} 番号が 8 進数である文字、無制限 \x7f 番号が 2 桁の 16 進数である文字、最大 \xFF \x{263a} 番号が 16 進数である文字、無制限 \cx Control-x \N{name} 名前つき Unicode 文字または文字並び \N{U+263D} 16 進数による Unicode 文字 =begin original \l Lowercase next character \u Titlecase next character \L Lowercase until \E \U Uppercase until \E \F Foldcase until \E \Q Disable pattern metacharacters until \E \E End modification =end original \l 次の文字を小文字にします \u 次の文字をタイトル文字にします \L \E まで小文字にします \U \E まで大文字にします \F \E まで畳み込み文字にします \Q \E までパターンのメタ文字を無効にします \E 修正を終了します =begin original For Titlecase, see L. =end original タイトル文字にについては L を参照してください。 =begin original This one works differently from normal strings: =end original この 1 つは通常の文字列とは異なった働きをします: =begin original \b An assertion, not backspace, except in a character class =end original \b 文字クラスの中以外では、表明であってバックスペースではありません =head2 CHARACTER CLASSES (文字クラス) =begin original [amy] Match 'a', 'm' or 'y' [f-j] Dash specifies "range" [f-j-] Dash escaped or at start or end means 'dash' [^f-j] Caret indicates "match any character _except_ these" =end original [amy] 'a', 'm', 'y' のいずれかにマッチ [f-j] ダッシュは「範囲」を指定します [f-j-] エスケープされるか、最初か最後にあるダッシュは「ダッシュ」を意味します [^f-j] キャレットは「これら以外にマッチ」を示します =begin original The following sequences (except C<\N>) work within or without a character class. The first six are locale aware, all are Unicode aware. See L and L for details. =end original (C<\N> 以外の)以下のシーケンスは文字クラス内でもそれ以外でも動作します。 最初の 6 つはロケールの影響を受け、全ては Unicode の影響を受けます。 詳細については L と L を参照してください。 =begin original \d A digit \D A nondigit \w A word character \W A non-word character \s A whitespace character \S A non-whitespace character \h An horizontal whitespace \H A non horizontal whitespace \N A non newline (when not followed by '{NAME}'; experimental; not valid in a character class; equivalent to [^\n]; it's like '.' without /s modifier) \v A vertical whitespace \V A non vertical whitespace \R A generic newline (?>\v|\x0D\x0A) =end original \d 数値 \D 非数値 \w 単語文字 \W 非単語文字 \s 空白文字 \S 非空白文字 \h 水平空白文字 \H 非水平空白文字 \N 非改行 ('{NAME}' に引き続いていない場合; 実験的; 文字クラスでは 不正; [^\n] と等価; /s なしの場合の '.' と同様) \v 垂直空白文字 \V 非垂直空白文字 \R 一般的な改行 (?>\v|\x0D\x0A) =begin original \C Match a byte (with Unicode, '.' matches a character) \pP Match P-named (Unicode) property \p{...} Match Unicode property with name longer than 1 character \PP Match non-P \P{...} Match lack of Unicode property with name longer than 1 char \X Match Unicode extended grapheme cluster =end original \C 1 バイトにマッチする (Unicode では、'.' は文字にマッチする) \pP P の名前の (Unicode) プロパティ \p{...} 1 文字より長い名前の Unicode プロパティにマッチする \PP 非 P にマッチする \P{...} 1 文字より長い名前の Unicode プロパティがないものにマッチする \X Unicode の拡張書記素クラスタにマッチする =begin original POSIX character classes and their Unicode and Perl equivalents: =end original POSIX 文字クラスと、それに対する Unicode と Perl の相当物は: ASCII- Full- POSIX range range backslash [[:...:]] \p{...} \p{...} sequence Description =begin original ----------------------------------------------------------------------- alnum PosixAlnum XPosixAlnum Alpha plus Digit alpha PosixAlpha XPosixAlpha Alphabetic characters ascii ASCII Any ASCII character blank PosixBlank XPosixBlank \h Horizontal whitespace; full-range also written as \p{HorizSpace} (GNU extension) cntrl PosixCntrl XPosixCntrl Control characters digit PosixDigit XPosixDigit \d Decimal digits graph PosixGraph XPosixGraph Alnum plus Punct lower PosixLower XPosixLower Lowercase characters print PosixPrint XPosixPrint Graph plus Print, but not any Cntrls punct PosixPunct XPosixPunct Punctuation and Symbols in ASCII-range; just punct outside it space PosixSpace XPosixSpace [\s\cK] PerlSpace XPerlSpace \s Perl's whitespace def'n upper PosixUpper XPosixUpper Uppercase characters word PosixWord XPosixWord \w Alnum + Unicode marks + connectors, like '_' (Perl extension) xdigit ASCII_Hex_Digit XPosixDigit Hexadecimal digit, ASCII-range is [0-9A-Fa-f] =end original ----------------------------------------------------------------------- alnum PosixAlnum XPosixAlnum Alpha と Digit alpha PosixAlpha XPosixAlpha 英字 ascii ASCII 任意の ASCII 文字 blank PosixBlank XPosixBlank \h 水平空白; 全種類は \p{HorizSpace} とも (GNU 拡張) cntrl PosixCntrl XPosixCntrl 制御文字 digit PosixDigit XPosixDigit \d 数字 graph PosixGraph XPosixGraph Alnum と Punct lower PosixLower XPosixLower 小文字 print PosixPrint XPosixPrint Graph と Print、しかし Cntrl は含まない punct PosixPunct XPosixPunct ASCII の範囲の句読点と シンボル; 単にその外側の punct space PosixSpace XPosixSpace [\s\cK] PerlSpace XPerlSpace \s Perl の空白の定義 upper PosixUpper XPosixUpper 大文字 word PosixWord XPosixWord \w Alnum + Unicode マーク + '_' のような接続文字 (Perl 拡張) xdigit ASCII_Hex_Digit XPosixDigit 16 進数; ASCII の範囲では [0-9A-Fa-f] =begin original Also, various synonyms like C<\p{Alpha}> for C<\p{XPosixAlpha}>; all listed in L =end original また、C<\p{XPosixAlpha}> のための C<\p{Alpha}> のような、さまざまな 同義語があります; 全ての一覧は L にあります。 =begin original Within a character class: =end original 文字クラスの中では: POSIX traditional Unicode [:digit:] \d \p{Digit} [:^digit:] \D \P{Digit} =head2 ANCHORS (アンカー) =begin original All are zero-width assertions. =end original すべてゼロ幅の表明です。 =begin original ^ Match string start (or line, if /m is used) $ Match string end (or line, if /m is used) or before newline \b Match word boundary (between \w and \W) \B Match except at word boundary (between \w and \w or \W and \W) \A Match string start (regardless of /m) \Z Match string end (before optional newline) \z Match absolute string end \G Match where previous m//g left off \K Keep the stuff left of the \K, don't include it in $& =end original ^ 文字列(/m が指定されている場合には行)の先頭にマッチします $ 文字列(/m が指定されている場合には行)の終端もしくは改行の前にマッチします \b 単語境界(\w と ¥W の間)にマッチします \B 単語境界以外(\w と \w の間か \W と \W の間)にマッチします \A 文字列の先頭(/m には影響されません)にマッチします \Z 文字列の末尾(省略可能な改行の前)にマッチします \z 文字列の本当の末尾にマッチします \G 前回の m//g のマッチした場所の末尾にマッチします =head2 QUANTIFIERS (量指定子) =begin original Quantifiers are greedy by default and match the B leftmost. =end original 量指定子はデフォルトでは貪欲で、 一番左から B<一番長く> マッチします。 =begin original Maximal Minimal Possessive Allowed range ------- ------- ---------- ------------- {n,m} {n,m}? {n,m}+ Must occur at least n times but no more than m times {n,} {n,}? {n,}+ Must occur at least n times {n} {n}? {n}+ Must occur exactly n times * *? *+ 0 or more times (same as {0,}) + +? ++ 1 or more times (same as {1,}) ? ?? ?+ 0 or 1 time (same as {0,1}) =end original 最大 最小 所有格 範囲 ------- ------- ---------- ------------- {n,m} {n,m}? {n,m}+ 最低 n 回、m 回以内出現 {n,} {n,}? {n,}+ 最低 n 回出現 {n} {n}? {n}+ 正確に n 回出現 * *? *+ 0 回以上 ({0,} と同じ) + +? ++ 1 回以上 ({1,} と同じ) ? ?? ?+ 0 回または 1 回 ({0,1} と同じ) =begin original The possessive forms (new in Perl 5.10) prevent backtracking: what gets matched by a pattern with a possessive quantifier will not be backtracked into, even if that causes the whole match to fail. =end original (Perl 5.10 で導入された) 所有格はバックトラックを抑制します: 所有格量指定子が付いたパターンでマッチした場合、バックトラックはしません; たとえこれによってマッチ全体が失敗することになってもです。 =begin original There is no quantifier C<{,n}>. That's interpreted as a literal string. =end original C<{,n}> という量指定子はありません。 これはリテラルな文字列として扱われます。 =head2 EXTENDED CONSTRUCTS (拡張構造) =begin original (?#text) A comment (?:...) Groups subexpressions without capturing (cluster) (?pimsx-imsx:...) Enable/disable option (as per m// modifiers) (?=...) Zero-width positive lookahead assertion (?!...) Zero-width negative lookahead assertion (?<=...) Zero-width positive lookbehind assertion (?...) Grab what we can, prohibit backtracking (?|...) Branch reset (?...) Named capture (?'name'...) Named capture (?P...) Named capture (python syntax) (?{ code }) Embedded code, return value becomes $^R (??{ code }) Dynamic regex, return value used as regex (?N) Recurse into subpattern number N (?-N), (?+N) Recurse into Nth previous/next subpattern (?R), (?0) Recurse at the beginning of the whole pattern (?&name) Recurse into a named subpattern (?P>name) Recurse into a named subpattern (python syntax) (?(cond)yes|no) (?(cond)yes) Conditional expression, where "cond" can be: (?=pat) look-ahead (?!pat) negative look-ahead (?<=pat) look-behind (?) named subpattern has matched something ('name') named subpattern has matched something (?{code}) code condition (R) true if recursing (RN) true if recursing into Nth subpattern (R&name) true if recursing into named subpattern (DEFINE) always false, no no-pattern allowed =end original (?#text) コメント (?:...) 部分正規表現を捕捉することなくグループ化します (クラスター) (?imxs-imsx:...) オプションを有効/無効にする (m// 修飾子のものと同じ) (?=...) ゼロ幅の肯定先読み表明 (?!...) ゼロ幅の否定先読み表明 (?<=...) ゼロ幅の肯定後読み表明 (?...) 出来うる限りマッチし、バックトラックしない (?|...) 分岐のリセット (?...) 名前付き捕捉 (?'name'...) 名前付き捕捉 (?P...) 名前付き捕捉 (python 文法) (?{ code }) 埋め込みコード。 戻り値は $^R に格納されます (??{ code }) 動的正規表現。戻り値は正規表現として扱われます (?N) サブパターン番号 N に再帰する (?-N), (?+N) N 個前/後のサブパターンに再帰する (?R), (?0) パターン全体の先頭に再帰する (?&name) 名前付きサブパターンに再帰する (?P>name) 名前付きサブパターンに再帰する (python 文法) (?(cond)yes|no) (?(cond)yes) 条件式; "cond" で指定できるのは: (?=pat) 前方参照 (?!pat) 前方参照の否定 (?<=pat) 後方参照 (?) 名前付きサブルーチンが何かにマッチした ('name') 名前付きサブルーチンが何かにマッチした (?{code}) コード条件 (R) 再帰したら真 (RN) N 番目のサブパターンに再帰したら真 (R&name) 名前付きサブパターンに再帰したら真 (DEFINE) 常に偽; パターンなしは許されない =head2 VARIABLES (変数) =begin original $_ Default variable for operators to use =end original $_ 演算子が使用するデフォルトの変数 =begin original $` Everything prior to matched string $& Entire matched string $' Everything after to matched string =end original $` マッチした文字列に先行する部分 $& マッチした文字列全体 $' マッチした文字列に後続する部分 =begin original ${^PREMATCH} Everything prior to matched string ${^MATCH} Entire matched string ${^POSTMATCH} Everything after to matched string =end original ${^PREMATCH} マッチした文字列に先行する部分 ${^MATCH} マッチした文字列全体 ${^POSTMATCH} マッチした文字列に後続する部分 =begin original The use of C<$`>, C<$&> or C<$'> will slow down B regex use within your program. Consult L for C<@-> to see equivalent expressions that won't cause slow down. See also L. Starting with Perl 5.10, you can also use the equivalent variables C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}>, but for them to be defined, you have to specify the C

(preserve) modifier on your regular expression. =end original C<$`>, C<$&>, C<$'> のいずれかを使うと、プログラム中の B<全ての> 正規表現の 速度が低下します。 速度低下を引き起こさない、等価な表現のためには、L の C<@-> を 調べてみてください。 また、L も参照してください。 Perl 5.10 から、等価な変数である C<${^PREMATCH}>, C<${^MATCH}>, C<${^POSTMATCH}> も使えますが、これらが定義されるには、正規表現に C

(保存(preserve)) 修飾子をつける必要があります。 =begin original $1, $2 ... hold the Xth captured expr $+ Last parenthesized pattern match $^N Holds the most recently closed capture $^R Holds the result of the last (?{...}) expr @- Offsets of starts of groups. $-[0] holds start of whole match @+ Offsets of ends of groups. $+[0] holds end of whole match %+ Named capture groups %- Named capture groups, as array refs =end original $1, $2 ... X 番目の捕捉された式を保持します $+ 最後にかっこで囲まれたパターンマッチ $^N 最も近くに閉じた捕捉を保持します $^R 最後の (?{...}) 式の結果を保持します @- グループの先頭からのオフセット。 $-[0] はマッチ全体の先頭です @+ グループの末尾からのオフセット。 $+[0] はマッチ全体の末尾です %+ 名前付き捕捉グループ %- 配列リファレンスとしての名前付き捕捉グループ =begin original Captured groups are numbered according to their I paren. =end original 捕捉したグループは I<開き> かっこの順番で番号付けされます。 =head2 FUNCTIONS (関数) =begin original lc Lowercase a string lcfirst Lowercase first char of a string uc Uppercase a string ucfirst Titlecase first char of a string fc Foldcase a string =end original lc 文字列を小文字にします lcfirst 文字列の最初の文字を小文字にします uc 文字列を大文字にします ucfirst 文字列の最初の文字を Titlecase にします fc 文字列を畳み込み文字にします =begin original pos Return or set current match position quotemeta Quote metacharacters reset Reset ?pattern? status study Analyze string for optimizing matching =end original pos カレントのマッチ位置を返したり設定したりします quotemeta メタ文字をクォートします reset ?pattern? の状態をリセットします study マッチングの最適化のために文字列を調べます =begin original split Use a regex to split a string into parts =end original split 文字列を分割するために正規表現を使います =begin original The first five of these are like the escape sequences C<\L>, C<\l>, C<\U>, C<\u>, and C<\F>. For Titlecase, see L; For Foldcase, see L. =end original これらの最初の五つは、エスケープシーケンス C<\L>, C<\l>, C<\U>, C<\u>, C<\F> と似ています。 タイトル文字については、L を参照してください; 畳み込み文字については、L を参照してください。 =head2 TERMINOLOGY (用語) =head3 Titlecase (タイトル文字) =begin original Unicode concept which most often is equal to uppercase, but for certain characters like the German "sharp s" there is a difference. =end original Unicode の概念で、ほとんどの場合は大文字と同じですが、ドイツ語の "sharp s" のような特定の文字については異なります。 =head3 Foldcase (畳み込み文字) =begin original Unicode form that is useful when comparing strings regardless of case, as certain characters have compex one-to-many case mappings. Primarily a variant of lowercase. =end original 大文字小文字に関わらず文字列を比較するときに有用な Unicode の形式です; ある種の文字は複雑な 1 対多大文字小文字マッピングを持つからです。 主に小文字の変種です。 =head1 AUTHOR Iain Truskett. Updated by the Perl 5 Porters. This document may be distributed under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * =begin original L for a tutorial on regular expressions. =end original 正規表現のチュートリアルである L。 =item * =begin original L for a rapid tutorial. =end original 手っ取り早いチュートリアルである L。 =item * =begin original L for more details. =end original さらなる詳細である L。 =item * =begin original L for details on the variables. =end original 変数に関する詳細である L。 =item * =begin original L for details on the operators. =end original 演算子の詳細である L。 =item * =begin original L for details on the functions. =end original 関数の詳細である L。 =item * =begin original L for FAQs on regular expressions. =end original 正規表現に関する FAQ である L。 =item * =begin original L for a reference on backslash sequences. =end original バックスラッシュシーケンス の参考資料である L。 =item * =begin original L for a reference on character classes. =end original 文字クラスの参考資料である L。 =item * =begin original The L module to alter behaviour and aid debugging. =end original 振る舞いの変更とデバッグの補助のための L モジュール。 =item * L =item * =begin original L, L, L and L for details on regexes and internationalisation. =end original 正規表現や国際化に関する詳細である L, L, L, L。 =item * =begin original I by Jeffrey Friedl (F) for a thorough grounding and reference on the topic. =end original この話題に関する完全な背景と参考資料である Jeffrey Friedl による書籍 I (F) (O'Reillyから出版: ISBN 1556592-257-3) (日本語版は「詳説 正規表現」ISBN4-87311-130-7 (第二版のもの))。 =back =head1 THANKS David P.C. Wollmann, Richard Soderberg, Sean M. Burke, Tom Christiansen, Jim Cromie, and Jeffrey Goff for useful advice. =cut =begin meta Translate: KIMURA Koichi Update: SHIRAKATA Kentaro (5.10.0-) Status: completed =end meta