regular expression matching 
Author Message
 regular expression matching

Is there anything in O/S2 REXX that can do regular expression pattern
matching

Thanks
Chris Stolpe



Fri, 21 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:

> Is there anything in O/S2 REXX that can do regular expression pattern
> matching

Perhaps a more interesting question is: does anyone have a standard REXX
implementation of a function that implements a regular expression
comparison of a string -- e.g. a function RegExp(Needle, Haystack [,
Start]) that works like POS(Needle, Haystack [, Start])?

--
                                        -- Aron

        "Sometimes the magic works, sometimes it doesn't."
                -- Chief Dan George, in "Little Big Man"

        NB: Om du vil svare med e-post, m? du fjerne "spam-block." fr?
adressa mi.
        NB: If you want to reply by e-mail, you will have to remove the
"spam-block." from my address.



Sat, 22 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:


> > Is there anything in O/S2 REXX that can do regular expression pattern
> > matching

> Perhaps a more interesting question is: does anyone have a standard REXX
> implementation of a function that implements a regular expression
> comparison of a string -- e.g. a function RegExp(Needle, Haystack [,
> Start]) that works like POS(Needle, Haystack [, Start])?

Check out REXXLIB.DLL from Quercus.  I heartily commend the package,
especially for the price.

Doug Rickman
Global Hydrology and Climate Center
Marshall Space Flight Center, NASA



Sat, 22 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:



> > > Is there anything in O/S2 REXX that can do regular expression pattern
> > > matching

> > Perhaps a more interesting question is: does anyone have a standard REXX
> > implementation of a function that implements a regular expression
> > comparison of a string -- e.g. a function RegExp(Needle, Haystack [,
> > Start]) that works like POS(Needle, Haystack [, Start])?

> Check out REXXLIB.DLL from Quercus.  I heartily commend the package,
> especially for the price.

Thanks for the suggestion, but a DLL doesn't work when the operating
system is Linux. I believe that the C code for a regular expression
search is freely available (somewhere). Someone has probably translated
it into REXX, and it would be nice if the REXX implementation were to be
made available.

--
                                        -- Aron

        "Sometimes the magic works, sometimes it doesn't."
                -- Chief Dan George, in "Little Big Man"

        NB: Om du vil svare med e-post, m? du fjerne "spam-block." fr?
adressa mi.
        NB: If you want to reply by e-mail, you will have to remove the
"spam-block." from my address.



Sun, 23 Apr 2000 03:00:00 GMT  
 regular expression matching


Quote:
>Thanks for the suggestion, but a DLL doesn't work when the operating
>system is Linux. I believe that the C code for a regular expression
>search is freely available (somewhere). Someone has probably translated
>it into REXX

This has been on a "generic wishlist" for some time, but has never been done
as far as I know.
--

------ http://www.comlab.ox.ac.uk/oucl/users/ian.collier/imc.html

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .



Mon, 24 Apr 2000 03:00:00 GMT  
 regular expression matching


Quote:

>>Thanks for the suggestion, but a DLL doesn't work when the operating
>>system is Linux. I believe that the C code for a regular expression
>>search is freely available (somewhere). Someone has probably translated
>>it into REXX

>This has been on a "generic wishlist" for some time, but has never been done
>as far as I know.
>--

>------ http://www.*-*-*.com/

>New to this group?  Answers to frequently-asked questions can be had from
> http://www.*-*-*.com/

 I just picked up this thread and probably miss the whole point.
One could take the GNU source code for Grep and put it into a
Rexx dll for whatever interpreter on whatever OS.
 I just don't see the point.  Pipe Rexx stdout into Grep and be done with
it.  It would be nice to have the PERL builtin regex but not necessary.

Jim
{*filter*}NET.PAIR.COM



Tue, 25 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:
> I just picked up this thread and probably miss the whole point.
>One could take the GNU source code for Grep and put it into a
>Rexx dll for whatever interpreter on whatever OS.
> I just don't see the point.  Pipe Rexx stdout into Grep and be done with
>it.  It would be nice to have the PERL builtin regex but not necessary.

It is rather a pain to pipe into grep and then read the results via the queue.
It would be much nicer if one could grep a complex (stemmed) variable's
elements. However, in keeping with one of the REXX language's original
purposes, I think regex handling is too complicated for novice or
occasional users to learn and remember. Of course, the same could be
said for Object REXX's extended syntax. But I digress...

However, I have used Perl's grep function and have found it to be a lot
slower than having the Unix egrep command do the grepping and piping the
output back into Perl. While Perl's regex handling is wonderful, it
doesn't mean it is the only thing that can do the job.

Stephen Rondeau



Tue, 25 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:
>> Is there anything in O/S2 REXX that can do regular expression pattern
>> matching
>Perhaps a more interesting question is: does anyone have a standard REXX
>implementation of a function that implements a regular expression
>comparison of a string -- e.g. a function RegExp(Needle, Haystack [,
>Start]) that works like POS(Needle, Haystack [, Start])?

As REXX as a scripting language is intented to be the *glue* between the
operating system commands there maybe a way around the lack by using
programs which do the job. At least it is possible with the general
available utility 'grep' to find out, wether a regexp matches another
string or not (the script eventually may be improved by replacing the
explicit file with pipes):


   PURPOSE:
   check, wether a needle is found in the haystack by
   using the standard gnu utility grep for regular expression match

   RETURNS:
   true (1) if found or false (0) if not

   INPUT:
   needle must be specified in ""

   EXAMPLE:
   s) called from commandline
   regexpmatch "[fg]o[oa]ls a" no fools around
      returns 1
   regexpmatch "[fg]o[oa]ls f" no goals found
      returns 1  
   regexpmatch "[fg]o[oa]ls a" no foams about
     returns 0

   b) called as a function in another script
   needle="[fg]o[oa]ls a"
   haystack=" no fools around"
   arglist=""""needle"""" haystack
   found=regexpmatch( arglist)

   REQUIRES:
   grep (found as GNU utility)
 */
signal on novalue
parse source myos mytype myfullname
parse value filespec( "name", myfullname) with myname ".cmd"
haystackfile=myname".tmp"

parse arg """"needle"""" haystack
select
 when (mytype == "COMMAND") then
   do
      called_as_function = 0
   end
 when (mytype == "FUNCTION") then
   do
      called_as_function = 1
   end
 otherwise /* SUBROUTINE */
    called_as_function = 0
end

if \called_as_function then
do
   say "needle="needle
   say "haystack="haystack
end

call stream haystackfile, "command", "open write"
call lineout haystackfile, haystack, 1
call stream haystackfile, "command", "close"


/* grep returns with exit code 0 if found and 1 if not found */
found = (rc == 0)

if \called_as_function then
do
   if (found) then
      answer = "is"
   else
      answer = "is not"

   say "needle "answer" found in haystack"
end
exit found

The following script shows the usage from another script

/* testregexpmatch -- */
say "input="arg(1)
parse arg """"needle"""" haystack
say "needle="needle
say "haystack="haystack
arglist=""""needle""""haystack
say "new arglist="arglist
found=regexpmatch( arglist)
say "found="found

--

Juelicher Str. 299, D-52070 Aachen, Germany,   Phone: 49-241-962005



Thu, 27 Apr 2000 03:00:00 GMT  
 regular expression matching


We're on the same page but here is my interpretation.

Quote:
>It is rather a pain to pipe into grep and then read the results via the queue.

Doesn't get any easier than piping STDIN, STDOUT, STDERR.  Learn that
and you're a scripting god.

Quote:
>It would be much nicer if one could grep a complex (stemmed) variable's
>elements.

How do you return the results assuming you could grep the stem?
How about a file?  It would be simple to grep a string so it would
would be each stem element or each file record.  Grep also has some
extended parameters that are hard to match in a simle program such
records before or after the grep match.

Quote:
>However, in keeping with one of the REXX language's original
>purposes, I think regex handling is too complicated for novice or
>occasional users to learn and remember.

IMHO Rexx was created as a simple to learn procedural language.
At that time, COWLISHAW didn't know how to spell UNIX.  Regex
can be as simple or as complicated as needed.  You don't understand
Regex you don't understand UNIX.

Quote:
>Of course, the same could be
>said for Object REXX's extended syntax. But I digress...

The Object model is more than extended syntax.  Once again
Object Rexx triumphs as the simple to learn Object language.

Quote:
>However, I have used Perl's grep function and have found it to be a lot
>slower than having the Unix egrep command do the grepping and piping the
>output back into Perl. While Perl's regex handling is wonderful, it
>doesn't mean it is the only thing that can do the job.

Perl is approaching bloatware.  It tries to isolate you from UNIX
or the OS platform but ultimately we know that is a deadend.  Not
to even mention the syntax kludge in Perl 5 for objects.  At least
IBM recognized the need to start over in Rexx for objects.  Give me
SED, AWK, REXX anyday over Perl.  In any version, Rexx will fit on
a diskette.  In any version, Perl needs to be installed on the OS.

Quote:
>Stephen Rondeau

Just my two cents worth on Perl and Rexx.  I've done development
in UNIX shops using Perl and Rexx on IBM os'es.  Give me a choice
and its Rexx.

---
Jim
{*filter*}NET.PAIR.COM



Fri, 28 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:
>> ...Pipe Rexx stdout into Grep and be done with
>> it.
>It is rather a pain to pipe into grep and then read the results via the queue.
>It would be much nicer if one could grep a complex (stemmed) variable's
>elements.

That's an easy task if you have 'the' (the hessling editor). 'The' uses
rexx as its scripting language, so you can do all rexx within 'the' as an
alternative arena to the os. You can fill in a stemmed variable, pass
it with a 'the'-builtin function to an os-program like grep with all its
features on regexp and 'the' presents you all output of grep in a
stemmed variable.

It's already there ready to be used. No reason for complaining and
sending wishful looks to heaven... Just put the things together.

Btw: 'the' is freeware and available on numerous platforms and works
with different rexxes. And it has a lively support. Just look at Marks
homepage: http://www.lightlink.com/hessling/

From the docs:
run_os(command[,stdin_stem[,stdout_stem[,stderr_stem]]])

       This function allows the macro writer to call an operating
       system command and have the standard streams; stdin , stdout
       and stderr redirected to or from REXX arrays.

[...]

       The stem name for stdout and stderr can be the same; the
       contents of the resulting output stems will consist of stdout
       and stderr in the order that the command generates this output.

   eg. to spell check the words "The Hessling Editr" with ispell
   ----------
   in.0 = 3
   in.1 = "The"
   in.2 = "Hessling"
   in.3 = "Editr"
   rc = run_os("ispell -a","in.","out.")
   ----------
   sets:
   out.0 --> 3
   out.1 --> "*"
   out.2 --> "#"
   out.3 --> "& edits edit editor"

should be easy to use grep the same way! You could use awk, perl or
whatever you like within 'the' that way.

enjoy
fjw
--

Juelicher Str. 299, D-52070 Aachen, Germany



Fri, 28 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:

>>However, in keeping with one of the REXX language's original
>>purposes, I think regex handling is too complicated for novice or
>>occasional users to learn and remember.
>IMHO Rexx was created as a simple to learn procedural language.
>At that time, COWLISHAW didn't know how to spell UNIX.  Regex
>can be as simple or as complicated as needed.

A number of the functions built into REXX can be seen as forms of
"regular expressions", like LEFT() and RIGHT(), which compare
quite nicely (imho) to "^" and "$" (if I'm not mistaken as to the
symbols used for those regexps).
One of the primary design goals of REXX was readability, aside
from easy to learn and use (and teach).
I have the feeling that Mike Cowlishaw certainly *did* know about
regular expressions back around the start of the 80's, but that
including them as used in Unix would *not* make REXX easy to read
for the casual general programmer/user.  And I know that *I* as
such a user most certainly will not remember what symbols to use
to define some regular expression.  And even if I did, I wouldn't
remember them after not having used them a month or so, whereas
LEFT() I can remember even after years of non-use (that is exactly
what happened to me, btw).

Now, if someone would write an external function (package) that
does all the common regular expressions, fine!  It would indeed
make life easier for those who want to use regexps.

Quote:
>You don't understand Regex you don't understand UNIX.

Speaking for myself, I can most certainly agree with that
statement.  Though I'd like to add piping, redirection, 'man', and
especially the use of one-character symbols to mean often quite
complicated things.

Regards,



Fri, 28 Apr 2000 03:00:00 GMT  
 regular expression matching

Quote:
>>It is rather a pain to pipe into grep and then read the results via the queue.

>Doesn't get any easier than piping STDIN, STDOUT, STDERR.  Learn that
>and you're a scripting god.

I've done it for over a decade. This god is bored.

Quote:
>>It would be much nicer if one could grep a complex (stemmed) variable's
>>elements.

>How do you return the results assuming you could grep the stem?

In a stemmed variable. I often felt that lack of stem support as
procedure args and function results was a design oversight. I know that
Object REXX corrects that, and did a good job of it.

Quote:
>How about a file?

It can already be done. REXX interfaces with the commands of the host
environment. If I wanted to code something quickly, I'd always choose
a well known command over a built-in function. But if I wanted
performance for items already in REXX variables, I would hope that the
function would perform the operation faster than writing the contents
of the variables to STDOUT, invoking a program, and reading results via the
queue.

Quote:
>>However, in keeping with one of the REXX language's original
>>purposes, I think regex handling is too complicated for novice or
>>occasional users to learn and remember.

>IMHO Rexx was created as a simple to learn procedural language.
>At that time, COWLISHAW didn't know how to spell UNIX.  

I can't speak for him, but I do know of the influence of Unix scripting
languages on EXEC, EXEC 2, and REXX. These things aren't developed in
a vacuum. I thank Mr. Cowlishaw for eliminating the need for those pesky
ampersands (and I wish Larry Wall would not have used dollar signs in
front of variables! And those darn semicolons!).

Quote:
>Regex can be as simple or as complicated as needed.  

The straightforward stuff can be done with existing functions and Parse.
It's the terse and therefore cryptic way of expressing the patterns that
makes it powerful. Most programmers love it; most people wanting to do
scripting with more powerful pattern matching probably wouldn't feel
that it was worth the effort because they'd need to relearn it every
time they occasionally used it.

Quote:
> You don't understand Regex you don't understand UNIX.

You simply don't understand that Unix is not regex. Regex is powerful
and very useful, but it isn't Unix nor is it the source of Unix's utility.

Quote:
>The Object model is more than extended syntax.  Once again
>Object Rexx triumphs as the simple to learn Object language.

Baloney. Look at NetRexx for a clean syntax and easy intro into an OO
language.

Quote:
>Just my two cents worth on Perl and Rexx.  I've done development
>in UNIX shops using Perl and Rexx on IBM os'es.  Give me a choice
>and its Rexx.

I agree that REXX is much simpler and easier to use than Perl.

Stephen Rondeau

P.S. It seems I had three cents worth.



Fri, 28 Apr 2000 03:00:00 GMT  
 regular expression matching



%
% A number of the functions built into REXX can be seen as forms of
% "regular expressions", like LEFT() and RIGHT(), which compare
% quite nicely (imho) to "^" and "$" (if I'm not mistaken as to the
% symbols used for those regexps).

In a limited sense, this is true. The awk expressions
 x ~ "^heigh ho"
 x ~ "heigh ho$"
are equivalent to the rexx expressions
 left(x,8) = "heigh ho"
 right(x,8) = "heigh ho"

But more complicated regular expressions are more difficult to express in
Rexx, and sometimes the regular expression is clearer. The trouble is
that every common program that makes use of regular expressions (I'm
thinking grep, egrep. sed, awk, lex, etc) uses a slightly different
syntax. Posix has standardised this with yet another syntax.

An example of something that would be easier with a form of regular
expression is:
 parse linein name :num: age height weight .
which could be used to parse names, ages, heights, and weights from an
input of the form
 Alfred C R Clarke 45 170 80
 James McNee 43 200 82

and so forth.
--

Patrick TJ McPhee
East York  Canada



Sat, 29 Apr 2000 03:00:00 GMT  
 regular expression matching


Quote:
>>The Object model is more than extended syntax.  Once again
>>Object Rexx triumphs as the simple to learn Object language.

>Baloney. Look at NetRexx for a clean syntax and easy intro into an OO
>language.

A pleasant alternative to learning JAVA syntax but then why not
bite the bullet and learn JAVA.  I'm not conviced NetRexx has the
horse power to stay up with JAVA or any other JAVA bytecode generator.
It's too bad SUN didn't champion Smalltalk but starting from scratch
was the best way to end around MS which remains to be seen.

---
Jim
{*filter*}NET.PAIR.COM



Sat, 29 Apr 2000 03:00:00 GMT  
 regular expression matching


:>>The Object model is more than extended syntax.  Once again
:>>Object Rexx triumphs as the simple to learn Object language.
:>
:>Baloney. Look at NetRexx for a clean syntax and easy intro into an OO
:>language.

Agreed.

And isn't it obvious that "the Man, the mind, the humanity" (if you'll
pardon the pledgerization) that produced REXX in the first place, is
very evident in NETREXX as it is being produced right now.

---------------------------------------------------------------------

---------------------------------------------------------------------
Hard work pays off in the future. Laziness pays off now.



Sat, 29 Apr 2000 03:00:00 GMT  
 
 [ 189 post ]  Go to page: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

 Relevant Pages 

1. regular expression matching in J ? (or APL)

2. regular expression: matching ( )

3. Regular expression matching with Halstenbach's REGEXP

4. Binding style and the universality of REs (was: Regular Expression Matching)

5. Regular Expression matching...

6. Regular Expressions: Match any character including newline and white space

7. Regular expression matching performance

8. Expect regular expression matching

9. regular expression match question

10. Expect's Interact and regular expression matching

11. Regular Expression matching question.

12. "Invert" regular expression matching

 

 
Powered by phpBB® Forum Software