Re: sample code from TPerlRegEx?
- From: "Goog" <goog@xxxxxxxx>
- Date: Thu, 24 Jul 2008 22:29:35 -0700
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" <crushfire2004@xxxxxxxxx> wrote in message news:op.uetpwlv8r9wvmw@xxxxxxxxxxxxxx
On Thu, 24 Jul 2008 21:22:13 +0700, Goog <goog@xxxxxxxx> 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)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
.
- Follow-Ups:
- Re: sample code from TPerlRegEx?
- From: Deli Soetiawan
- Re: sample code from TPerlRegEx?
- References:
- Re: sample code from TPerlRegEx?
- From: Deli Soetiawan
- Re: sample code from TPerlRegEx?
- Prev by Date: Re: sample code from TPerlRegEx?
- Next by Date: Re: sample code from TPerlRegEx?
- Previous by thread: Re: sample code from TPerlRegEx?
- Next by thread: Re: sample code from TPerlRegEx?
- Index(es):
Relevant Pages
|