RegExpMatch

From Soldat Community Wiki
Jump to: navigation, search

From the Scripting Manual

function RegExpMatch(Pattern, Source: string): boolean;

Parameter Info:
 Pattern (String): A POSIX extended regular expression.
 Source (String): Source string to be searched

Description:
 Searches source for a match to the regular expression given in pattern.
 To be honest, I have no clue how regexp strings work... 
 A friend requested regexp support so here it is. 
 Google is your friend if you need help with this.

Examples

var
  Text: string;
begin
  Text := 'regexptest test';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //true
  Text := 'RegExpTest test';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //false
  Text := 'regexptest ';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //false
  Text := 'regularexppressiontest test';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //true
  Text := 'hmph test';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //true
  Text := 'regexp test';
  if (RegExpMatch('^(reg(ular)?exp(pressions?)?test|hmph) .+$', Text)) then WriteLn('IT WORKED!'); //false
end;

External Links