Discussion:
sample code from TPerlRegEx?
(too old to reply)
Deli Soetiawan
2008-07-24 09:28:00 UTC
Permalink
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
2008-07-24 14:22:13 UTC
Permalink
Have a look at

http://www.regexbuddy.com/

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

Goog
Post by Deli Soetiawan
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/
Nick Hodges (Embarcadero)
2008-07-24 16:01:00 UTC
Permalink
Goog -- how are you?
--
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges
Alessandro Federici
2008-07-24 19:16:10 UTC
Permalink
Post by Nick Hodges (Embarcadero)
Goog -- how are you?
Who is Goog?
Nick Hodges (Embarcadero)
2008-07-24 19:27:45 UTC
Permalink
Post by Alessandro Federici
Post by Nick Hodges (Embarcadero)
Goog -- how are you?
Who is Goog?
The guy who wrote the g framework, of course. ;-)

http://g-framework.org/
--
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges
Deli Soetiawan
2008-07-25 01:18:11 UTC
Permalink
Post by Goog
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)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Goog
2008-07-25 05:29:35 UTC
Permalink
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
Post by Deli Soetiawan
Post by Goog
Have a look at
http://www.regexbuddy.com/
It's a superb product that should help you get your job done.
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)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Deli Soetiawan
2008-07-25 05:42:37 UTC
Permalink
Post by Goog
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...
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Bob S
2008-07-25 04:24:11 UTC
Permalink
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.
Deli Soetiawan
2008-07-25 05:50:00 UTC
Permalink
Post by Bob S
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.
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)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Loading...