Javascript-string-match
提供:Dev Guides
JavaScript文字列-match()メソッド
説明
このメソッドは、文字列を正規表現と照合するときに一致を取得するために使用されます。
構文
match()メソッドを使用するには、次の構文を使用します。
string.match( param )
引数の詳細
*param* -正規表現オブジェクト。
戻り値
- 正規表現に* gフラグが含まれていない場合、* regexp.exec(string)*と同じ結果を返します。
- 正規表現に* gフラグ*が含まれている場合、メソッドはすべての一致を含む配列を返します。
例
次の例を試してください。
<html>
<head>
<title>JavaScript String match() Method</title>
</head>
<body>
<script type = "text/javascript">
var str = "For more information, see Chapter 3.4.5.1";
var re =/(chapter \d+(\.\d)*)/i;
var found = str.match( re );
document.write(found );
</script>
</body>
</html>
出力
Chapter 3.4.5.1,Chapter 3.4.5.1,.1