Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sample code from TPerlRegEx?

1,083 views
Skip to first unread message

Deli Soetiawan

unread,
Jul 24, 2008, 5:28:00 AM7/24/08
to
hi there,

i've been test the RegEx component i download from
http://www.regular-expressions.info/delphi.html, it works well on matching
string but since i new to Regular Expression i need a sample code that can
pull out matching string from file and place it in the listbox (or other
component). so if anyone have a working sample, please share it :D

PS: code should work on binary or text file

thanks

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Goog

unread,
Jul 24, 2008, 10:22:13 AM7/24/08
to
Have a look at

http://www.regexbuddy.com/

It's a superb product that should help you get your job done.

Goog

"Deli Soetiawan" <crushf...@gmail.com> wrote in message
news:op.ueshwyctr9wvmw@loggic-prog...

Nick Hodges (Embarcadero)

unread,
Jul 24, 2008, 12:01:00 PM7/24/08
to
Goog -- how are you?

--
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges

Alessandro Federici

unread,
Jul 24, 2008, 3:16:10 PM7/24/08
to
"Nick Hodges (Embarcadero)" <nick....@codegear.com> wrote in message
news:4888a73c$1...@newsgroups.borland.com...

> Goog -- how are you?

Who is Goog?

Nick Hodges (Embarcadero)

unread,
Jul 24, 2008, 3:27:45 PM7/24/08
to
Alessandro Federici wrote:

The guy who wrote the g framework, of course. ;-)

http://g-framework.org/

Deli Soetiawan

unread,
Jul 24, 2008, 9:18:11 PM7/24/08
to
On Thu, 24 Jul 2008 21:22:13 +0700, Goog <go...@goog.com> wrote:

> Have a look at
> http://www.regexbuddy.com/
> It's a superb product that should help you get your job done.

what i mean was actual code for regex from file, maybe something like:

AssignFile(Fn, 'test.dat');
Reset(Fn);
While not Eof(Fn) do
begin
ReadLn(Fn, Data);
PerlRegEx.Subject := Data;
PerlRegEx.Match;
ListBox.Items.Add(PerlRegEx.MatchedExpression);
end;
CloseFile(Fn);

yeah something like reading all files and pull out match pattern from it,
i can do it with readln but it was to slow,
i can do with BlockRead but since the buffer was a array (like
array[1..512] of char) the regex can't get much match, if only anyone have
sample with FileStream or TStream it would be nice (kinda hard to find
reference about it in Win32, all i got was reference for .NET)

Bob S

unread,
Jul 25, 2008, 12:24:11 AM7/25/08
to

Deli, since this is thirdpartytools... have you seen DIRegEx:
http://www.yunqa.de/delphi/doku.php/products/regex/index?DokuWiki=8o6qiubnsnjuhdfcjk59fsli36

It's like 25 Euro for no source, and 75 Euro for source version. That should do what you want and has good documentation.

Goog

unread,
Jul 25, 2008, 1:29:35 AM7/25/08
to
Here is a method (ParseNaturalListings) from a class I made (TgbGoogle) to
pull web addresses from a google search results page:


procedure TgbGoogle.ParseNaturalListings;
begin
RegEx.Regex :=
'(?i)href="HTTP://(www\.)?([_a-z\d\-]+(\.[_a-z\d\-]+)?)/?"';
RegEx.Subject := ResponseHTML;
if RegEx.Match then
repeat
Kind := 1;
ResultHostName := LowerCase(RegEx.SubExpressions[2]);
AddSearchTermAreaResult;
until not RegEx.MatchAgain;
end;

RegEx is a property of type TPerlRegEx. Its Regex property gets assigned the
regular expression string, and its subject takes on the value of an entire
google results page represented as a string. Its Match method is called to
populate the ResultHostName property with the result of the second
subexpression. This continues until there are no more matches.

Since I suck at writing regular expressions, I use RegEx Buddy to help.

I hope this example helps you along. In your example, I think you might use
the TFileStream class to load the entire file into a stream, then, transfer
the contents of the stream to a string variable to use as the regex's
Subject property.

Goog


"Deli Soetiawan" <crushf...@gmail.com> wrote in message

news:op.uetpwlv8r9wvmw@loggic-prog...

Deli Soetiawan

unread,
Jul 25, 2008, 1:50:00 AM7/25/08
to

yes i have tried it, i even made demo application using that component
(based on SearchStream demo they have) just too bad, it was shareware, i
use my application for education purpose so i have to turn into freeware
component :D there was two freeware regex component, one was TRegExp from
regexpstudio.com and next was TPerlRegExp (i currently use for now)

Deli Soetiawan

unread,
Jul 25, 2008, 1:42:37 AM7/25/08
to
On Fri, 25 Jul 2008 12:29:35 +0700, Goog <go...@goog.com> wrote:

> I hope this example helps you along. In your example, I think you might
> use the TFileStream class to load the entire file into a stream, then,
> transfer the contents of the stream to a string variable to use as the
> regex's Subject property.

thanks for the code sample, it's very helpfull, btw what you told was
right, load entire file into a stream and use it as regex subject.
too bad the file was around 100 mb and it takes memory for assigning
entire file into a stream, btw it's ok, i just have to figure out how to
solve em.
take alook RegExBuddy, it can regex entire file in fast time :D, i just
dunno how to do em

or maybe i can open file in TMemo and start RegEx TMemo.Lines...

0 new messages