match
string string
match は 「元に戻す」が不可能、「照会」が不可能、「編集」が不可能 です。
第 1 文字列引数の正規表現と一致する、第 2 文字列引数の一部が返されます。この正規表現は連続する文字と一致する必要があります。一致しない場合は空の文字列("")が返されます。 正規表現は、検索パターンを指定する標準構文です。 この参照ページでは、正規表現の概要について説明します。 正規表現は、一致基準を定義する特殊文字が含まれる文字列です。最も単純な表現は、単なる文字列です(下の例 1 を参照)。 正規表現の基本的な構築ブロックは以下のとおりです。| . | 任意の 1 つのキャラクタにマッチします。 |
| * | 前の表現の 0 個以上のものにマッチします。 |
| + | 前の表現の 1 個以上のものにマッチします。 |
| ^ | 表現を行の先頭に合わせます(固定します)。 |
| $ | 表現を行の末尾に合わせます(固定します)。 |
| \ | エスケープ文字。「*」などの特殊文字の実際の文字と突き合わせる場合、その特殊文字の前で使用します。MEL 文字列が、最初に解析する場合、「\」を使用する特殊文字を解決することに注意してください。このため文字「\」を表現内で使用するには、エスケープを付けて(「\\」)突き合わせに渡す必要があります。 |
| [...] | カッコで囲まれたキャラクタの 1 つにマッチします。- で区切られた一対のキャラクタは、辞書上でその対の間に入るすべてのキャラクタ(その対自身を含む)とマッチします。"[" に続く最初のキャラクタが "^" である場合は、囲まれていない任意のキャラクタがマッチします。- は、最初か最後のキャラクタとして置くことで、キャラクタ セットに含めることができます。 |
| (...) | エクスプレッションの一部をグループ化します。 |
| string | マッチする文字列 |
// Example 1: a simple string match
//
match "this" "this is a test";
// Result: this //
// Example 2: using '*' and '+'
//
match "a*b*" "abbcc";
// Result: abb //
match "a*b*" "bbccc";
// Result: bb //
match "a+b+" "abbcc";
// Result: abb //
// The following will fail because there has to be at least one "a"
match "a+b+" "bbccc";
// Example 3: anchoring to the start and end of the line
//
// This matches "the", only if it is at the start of the line
match "^the" "the red fox";
// Result: the //
// The following fails
match "^the" "chase the red fox";
// This matches "fox", only if it is at the end of the line
match "fox$" "the red fox";
// The following fails
match "fox$" "the red fox hides";
// Example 4: matching ranges of characters
//
match "[0-9]+" "sceneRender019.iff";
// Result: 019 //
// Example 5: using ()
//
match "(abc)+" "123abcabc456";
// Result: abcabc //
// Example 6: the escape charater
//
// as mentioned above, MEL parses '\' escape characters in strings. So,
// to pass an actual '\' character through to match, you must escape it.
//
// The following regular expression is really "\^.", but we have to escape
// the '\'.
//
match("\\^.", "ab^c");
// Result: ^c
//