[Demo] Searching with regular expressions

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 14263
Joined: Sat Aug 27, 2005 10:28 am

[Demo] Searching with regular expressions

Post by Sergey Tkachenko » Wed Sep 26, 2018 7:04 pm

Searching with regular expressions
(177.49 KiB) Downloaded 52 times
This ZIP file contains two demo projects.

1) Search from the cursor position
TRichView-Regular-Expressions.png (65.25 KiB) Viewed 1147 times
2) Search and highlight all occurrences
TRichView-Regular-Expressions-Ex.jpg (185.9 KiB) Viewed 1147 times
The both demo projects use the same technique. They save content to a sting that has 1:1 correspondence to the original content. Regular expressions are searched in this string using TRegEx. After finding, they are marked in the original document.

This demo requires Delphi XE or newer (because TRegEx was introduced in this version of Delphi).
The first version of this demo is very fast even for huge documents.
The second version may be slow, because TRegEx.Matches is slow if it returns a large count of matches (in real application, you can use TRegEx.Match and then a cycle of Match.NextMatch, and limit a count of results).
For results highlighting, the second demo uses the same mechanism as for live spelling checking (instead of wavy underlines, it draws semitransparent color rectangles).

Post Reply