用規則運算式搜尋指定的字串,并用指定的字串取代。如果設定的是 Global 屬性,這個方法會取代字串中所有可能的符合。
strResult = reg.Replace( strText, strReplace );
strResult = reg.Replace( strText, strReplace )
strText
指定要用規則運算式搜尋的字串。
strReplace
指定要取代為的字串。
返回新的字串。
re = editor.regex;
re.Engine = eeExFindRegexOnigmo;
re.Pattern = "([A-Z0-9._%+-]+)@([A-Z0-9.-]+\\.[A-Z]{2,})";
re.IgnoreCase = true;
re.OnlyWord = false;
strOrg = "The email address is john@test.com."
strNew = re.Replace( strOrg, "\\1 at \\2" );
if( strOrg != strNew ) {
alert( strNew );
}
Set re = editor.regex
re.Engine = eeExFindRegexOnigmo
re.Pattern = "([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})"
re.IgnoreCase = True
re.OnlyWord = False
strOrg = "The email address is john@test.com."
strNew = re.Replace( strOrg, "\1 at \2" )
If strOrg <> strNew Then
alert( strNew )
End If
支持 EmEditor Professional Version 15.9 或之後的版本。