RegEx.ReplaceMatches

Top  Previous  Next

Finds text using regular expressions and replaces the matches.

 

Syntax

function RegEx.ReplaceMatches(Pattern: string; Replacement: string; Subject: string): string

 

Alternative Names

RE.ReplaceMatches
ibec_preg_Replace

 

Description

Attempts to match text using regular expressions and replaces the matching text.

 

The Pattern is the regular expression that will be used to match text in the Subject. All matched text will be replaced by the Replacement.

 

The Return Value is the text in the Subject parameter, but all matches have been replaced with the Replacement value.

 

See also

RegEx.FindMatches

 

Example

execute udsblock 

as

begin

  Subject = 'test m@nu.nl and then some z@example.com and more, @, test. finally fake@web.com';

  EMailMatch = '[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+';

 

  MyResults = null; /* Array.Create(''); */

 

  /* attempt to match e-mail addresses in the given text */

  RegEx.FindMatches(EMailMatch, Subject, MyResults);

 

  /* display the number of items found */

  GUI.ShowMessage('Items found: ' ||  Array.Length(MyResults)); 

  /* cycle the resulting array and show each entry */

  foreach (MyResults as foundval)

  do begin

   GUI.Showmessage('Following e-mail addres found: ' || foundval); 

 end;

 

  /* now, replace the e-mail addresses in the Subject with nospam@example.com */

  NewSubject = RegEx.ReplaceMatches(EMailMatch, 'nospam@example.com', Subject);

 

  GUI.ShowMessage('Modified text: ' || NewSubject);

end;