'------------------------------------------------ 'wshReplace.vbs 'WSHのRegExpを使った簡易な複数行置換マクロ '------------------------------------------------ Private Sub Main sRet = InputBox("置換パターンを入力してください", "簡易複数行置換マクロ", "s/置換前/置換後/gi") If Left(sRet, 2) <> "s/" Then Exit Sub '置換前切り出し iStart = 3 iEnd = InStr(iStart, sRet, "/") If iStart >= iEnd Then Exit Sub sBefore = Mid(sRet, iStart, iEnd - iStart) '置換後切り出し iStart = iEnd + 1 iEnd = InStr(iStart, sRet, "/") If iStart > iEnd Then Exit Sub sAfter = Mid(sRet, iStart, iEnd - iStart) 'RegExpオブジェクト生成 Set oRegExp = New RegExp '修飾子判定 iStart = iEnd + 1 If Instr(iStart, sRet, "g") Then oRegExp.Global = True If Instr(iStart, sRet, "i") Then oRegExp.IgnoreCase = True '置換処理 oRegExp.Pattern = sBefore If GetSelectedString(CLng(0)) = "" Then SelectAll InsText CStr(oRegExp.Replace(GetSelectedString(CLng(0)), sAfter)) Set oRegExp = Nothing End Sub Call Main