正規表現

「正規表現」の編集履歴(バックアップ)一覧はこちら

正規表現」(2010/04/20 (火) 01:14:55) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

・数字を検索  \d+  [0-9]+ ・桁数を範囲指定して数字を検索  \d{2,5}  (「\d」が2桁以上、5桁以下)  \d{2,}  (「\d」が2桁以上)  \d{2}  (「\d」が2桁) ・空行選択  ^\n ・一度に2つの文字列を検索  AAA|BBB ・メールアドレスを検索  [\w\d_-]+@[\w\d_-]+\.[\w\d._-]+  より厳しく  ^[a-zA-Z0-9!$&*.=^`|~#%'+\/?_{}-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4}$ ・URLを検索  http://[\w\d/%#$&?()~_.=+-]+ ・HTMLのタグを検索  例:<TABLE BORDER=1 WIDTH=800> (TABLEタグの場合)  <TABLE.*?>
**正規表現 ***正規表現を使ってパターンに一致するか調べる Dim re Set re = New RegExp re.Pattern = "^A.*$" If re.Test("ABC") Then WScript.Echo "matched" End If ***大文字小文字を区別 re.IgnoreCase = True ***文字列全体を検索対象にする場合 re.Global = True ***正規表現を使って一致する文字列を取得する Dim re, matches Set re = New RegExp re.Pattern = "^A.*$" Set matches = re.Execute("ABC") If matches.Count > 0 Then WScript.Echo matches(0) End If ***正規表現を使ってキャプチャした文字列を取得する Dim re, matches Set re = New RegExp re.Pattern = "^([A-F]+)_([A-F]+).+" Set matches = re.Execute("ABC_DEF_GHI") If matches.Count > 0 Then WScript.Echo matches.Item(0).SubMatches.Item(0) WScript.Echo matches.Item(0).SubMatches.Item(1) End If ***正規表現を使って文字列を置換する Dim re, matches Set re = New RegExp re.Pattern = "^ABC_" WScript.Echo re.Replace("ABC_DEF_GHI", "XXX_") ***正規表現を使って文字列を置換する(後方参照) Dim re, matches Set re = New RegExp re.Pattern = "^([A-Z]{2})(.*)" WScript.Echo re.Replace("ABCDE", "XX$2")

表示オプション

横に並べて表示:
変化行の前後のみ表示: