[fpc-pascal] Replacing parts of a string with TRegexpr

luciano de souza luchyanus at gmail.com
Thu Feb 22 14:38:58 CET 2018


Hello all,
I'd like to replace some part of a string acording to a pattern.
I know how to search and print the matches of a ER:

program test;
{$mode objfpc}{$H+}

uses
regexpr;

var
r: TRegexpr;

BEGIN
r := TRegexpr.create('(\d+)');
try
if r.exec('01 Brazil, 02 USA, 03 China') then
begin
repeat
writeln(r.match[0]);
until not r.ExecNext;
end
else
writeln('Pattern not found');
finally
r.free;
end;
END.

But how could I to substitute all "(\d+)", for example, to "xx".
The regexpr unit has some documentation in its source code, but
dispite this, I was not able to understand how to do it.

-- 
Luciano de Souza


More information about the fpc-pascal mailing list