Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Regular Expression "engine" for Borland Pascal?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 27th February 05:39
mhg
External User
 
Posts: 1
Default Regular Expression "engine" for Borland Pascal?



Many thanks to you all for your replies.

Marco van der Voort,'s freepascal reference looks interesting but
daunting, but I'll have a closer look at it. My command of C / C++ is
dodgy and insufficient to translate C code to Pascal.

I certainly agree with John Stockton's opinion that regexps should be
a standard language feature of (well, all) languages. I do use Delphi
rather than TP or BP these days, I only have Delphi 2 though which
doesn't have a bundled RegExp add-on. Is it available elsewhere?, if
so, I shall be grateful for a reference.

My current interest in Regexp is for a database query algorithm I am
trying to develop. I am looking specifically for two functions like
these:-

Function eregi(regexpstr: String, TargetStr:String): boolean;
begin
{returns true if TargetStr contains regexprStr}
end;

Function eregiReplace(regexpstr: String;
ReplaceStr:String;Oldstr:String): String;
begin
{returns a string where all matches of regexpstr in OldStr with
ReplaceStr}
end;

(An example of regexprStr is:-

regexprStr:= '^[a-zA-Z]+$; (* matches any string with 1 or more
letters and nothing else*)
)

Some months ago, I got into the world of web server-side scripting -
CGI and all that good stuff. I find traditional CGI programming
difficult to grasp, but the job is made much easier nowadays by PHP
{http://www.php.net/}, a powerful scripting language with just about
all the features a programmer wants - including Regexp, which
implements the two functions above. Unfortunately its impossible to
snatch the functions out of the PHP environment.

A couple of years ago, I came across Albert Graef's Tply - a Turbo
Pascal implementation of the Unix Lex and Yacc compiler makers tools.
(See http://www.musikwissenschaft.uni-mainz.de/~ag/tply/). The TPly
TPlex tool does have Regexpr Pascal code, but I've not found it
possible to dig out the bits needed to implement functions like those above.

--
Michael Glover - michael_glover@lineone.netxx
(Surrey, UK. http://www.users.globalnet.co.xx/~glover/ )
(Please change "xx" to "uk" to reply/access web site)
  Reply With Quote


  sponsored links


2 27th February 05:39
femme verbeek
External User
 
Posts: 1
Default Regular Expression "engine" for Borland Pascal?



AFAIK
You can download the personal version of Delphi for free on the Borland
site.


--
Femme
  Reply With Quote
3 27th February 05:40
marco van de voort
External User
 
Posts: 1
Default Regular Expression "engine" for Borland Pascal?


Regexp's are familiar and abundant. However could you to formulate _why_
you need such a terse syntax?


No. Regexp's are traditionally something of the C world, with their
interpreted IO. Some scripting languages started to use it also though.


Ah, but PHP is an interpreter. Then it makes some sense :-)

No TPLY is much more powerful parsing technique than a regex. Essentially
it is a superset. However traditionally it creates _compiled_ parsers, which
are larger, but faster.
  Reply With Quote
4 27th February 05:40
wolf behrenhoff
External User
 
Posts: 1
Default Regular Expression "engine" for Borland Pascal?


I think that REs became really popular with Perl. In Perl, REs are not
used in functions like in PHP but they are an integrated part of the
whole language. They are very useful but sometimes they tend to be a
little cryptic.
To make REs more readable, Perl allows "extended syntax" for REs which
allows you to make comments inside REs.

Example:
m/^(.{3,9})\d{2}x?/ (cryptic)

Readable version:
m/
^ # string begins with
.{3,9} # three to nine arbitrary characters
\d{2} # followed by 2 digits
x? # and optionally by x
/

What I want to say with this post is that REs don't have to be cryptic,
it is possible to use them and to be able to read them once they are
written! In Perl 6, there will be changes concerning REs to make them
better readable.

It should also be possible to use readable REs in Pascal-ish languages!
One could for example put all these things in a class and add procedures
which explain what to match instead of giving a regular-expression
string.

Wolf
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666