RegExp

正規表現(正則表現)を扱うオブジェクトです。match()やreplace()のパラメータとして指定できます。gオプションはグローバルマッチ、iオプションは英大文字と小文字を無視、mは改行時の先頭マッチなどの処理が可能(^, $)であることをを示します。

構文

正規表現オブジェクト = new RegExp(正規表現文字列, オプション)
文字列.match(/正規表現文字列/オプション)
文字列.replace(/正規表現文字列/オプション)

例文

<html>
 <head>
  <title>RegExp</title>
</head>
 <body>
  <script type="text/javascript"><!--
  txt = "Sample Text, RegExp sample"
  reObj = new RegExp("Sa....","gi");
  result = txt.match(reObj);
  document.write("1 : "+result+"<br>");
  result = txt.match(/Sa..../gi);
  document.write("2 : "+result+"<br>");
  // --></script>
 </body>
</html>

関連記事

スポンサーリンク

Time measure タイムメジャー

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る