Replace Method (Regex Object)¶
Searches the specified string for the regular expression and replace with the specified string. If the Global property is set, this method replaces all possible matches in the string. strText Specifies a string to search for the regular expression. strReplace Specifies a string to replace with. Returns the new string. Supported in EmEditor Professional Version 15.9 or later.¶
[JavaScript]¶
strResult = reg.Replace( strText, strReplace );
[VBScript]¶
strResult = reg.Replace( strText, strReplace )
Parameters¶
Return Values¶
Examples¶
[JavaScript]¶
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 );
}
[VBScript]¶
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
Version¶