So I am using the TRegExpr unit to try and match parts of strings and surround the matched strings in some HTML. Seems straight forward and maybe it is my expressions that are an issue so here is 2 of the various expressions I am using
Now I struggle with regular expressions but the .*tony.* I understand should match "xxxxxxxxxToNyxxxxxxx" or "tonyxxxxx" ?
And lazarus.* would match "lazarusxxxxxxxxxxx" but not "LaZarusxxxxxxxxxx" ?
I'm assuming those are ok enough for my current test.
The code to wrap the matched text has varried but currently I am at this point and I am getting very frustrated so here I am...
if Expression.Exec(Addresses) then begin
// Get the start and length of the matching text
matchStart := Expression.MatchPos[1];
matchLen := Expression.MatchLen[1];
// Surround the matching text with the HTML tags
formattedText := '<b><font color="#00FF00">' + Copy(Addresses, matchStart, matchLen) + '</font></b>';
// Replace the original matching text with the formatted text using the Substitute() method
formattedAddress := Expression.Substitute('<b><font color="#00FF00">$0</font></b>'); // substitute didnt work....
Sender.PostMessage(70, formattedAddress);
end;
And here was another thing I tried:
if myRegExpr.Exec(Addresses) then begin
// Get the full match
fullMatch := myRegExpr.Match[0];
WriteLn('full match: ' + fullMatch);
//while myRegExpr.ExecNext do begin
matchingText := myRegExpr.Match[1];
WriteLn('matching text: ' + matchingText);
// Get the index of the capture group within the full match
index := Pos(matchingText, fullMatch);
// Insert the formatted text into the full match at the appropriate index
formattedText := '<b><font color="#00FF00">' + matchingText + '</font></b>';
Insert(formattedText, fullMatch, index);
// Replace only the matched text with the formatted text
formattedAddress := StringReplace(Addresses, matchingText, formattedText, [rfReplaceAll, rfIgnoreCase]);
end;
I need a little direction on this.... Thank you.