Next: , Up: 正規表現   [Contents][Index]


35.3.1 正規表現の構文

Regular expressions have a syntax in which a few characters are special constructs and the rest are ordinary. An ordinary character is a simple regular expression that matches that character and nothing else. The special characters are ‘.’, ‘*’, ‘+’, ‘?’, ‘[’, ‘^’, ‘$’, and ‘\’; no new special characters will be defined in the future. The character ‘]’ is special if it ends a bracket expression (see later). The character ‘-’ is special inside a bracket expression. A ‘[:’ and balancing ‘:]’ enclose a character class inside a bracket expression. Any other character appearing in a regular expression is ordinary, unless a ‘\’ precedes it.

たとえば‘f’はスペシャル文字ではなく通常文字なので、‘f’は文字列‘f’にマッチして他の文字にはマッチしない正規表現です(これは文字列‘fg’にはマッチしないが、その文字列の部分にマッチする)。同様に‘o’は‘o’だけにマッチします。

任意の2つの正規表現abを結合することができます。結合した結果は文字列の先頭からある長さの文字列がaにマッチして、残りの文字列がbにマッチするような文字列にマッチする正規表現になります。

単純な例として文字列‘fo’だけにマッチする正規表現の構成要素‘fo’を取得するために正規表現‘f’と‘o’を結合できます。

This page has generated for branch:master, commit:762705fb24fd90db318f2e51c1e762452d26f7e2 to check Japanese translation.