Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Regular-expressions/Delphi/regular-expressions.delphi
Normal file
32
Task/Regular-expressions/Delphi/regular-expressions.delphi
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
program Regular_expressions;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$R *.res}
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
System.RegularExpressions;
|
||||
|
||||
const
|
||||
CPP_IF = '\s*if\s*\(\s*(?<COND>.*)\s*\)\s*\{\s*return\s+(?<RETURN>.+);\s*\}';
|
||||
PASCAL_IF = 'If ${COND} then result:= ${RETURN};';
|
||||
|
||||
var
|
||||
RegularExpression: TRegEx;
|
||||
str: string;
|
||||
|
||||
begin
|
||||
str := ' if ( a < 0 ) { return -a; }';
|
||||
|
||||
Writeln('Expression: '#10#10, str);
|
||||
|
||||
if RegularExpression.Create(CPP_IF).IsMatch(str) then
|
||||
begin
|
||||
Writeln(#10' Is a single If in Cpp:'#10);
|
||||
|
||||
Writeln('Translate to Pascal:'#10);
|
||||
str := RegularExpression.Create(CPP_IF).Replace(str, PASCAL_IF);
|
||||
Writeln(str);
|
||||
end;
|
||||
readln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue