RegExpMatch

From Soldat Community Wiki
Revision as of 10:54, 15 August 2012 by Freeman (talk | contribs) (Created page with "===From the Scripting Manual=== ''function RegExpMatch(Pattern, Source: string): boolean;'' '''Parameter Info:''' Pattern (String): A POSIX extended regular expression. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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