Discussion:
REXX enhancement idea #1 - regular expressions.
(too old to reply)
John McKown
2017-03-16 12:37:55 UTC
Permalink
Raw Message
I hope people are not too upset with me for discussing some enhancements in
REXX that I would like, which are mainly UNIX inspired. They should be made
functional in "regular" REXX as well, not like the UNIX shell only
functions such as lineout().

Regular expressions. Something akin to awk's match(), gsub(), and sub()
functions.
Ref: https://www.merriam-webster.com/dictionary/defenestration
[quote]
...
gsub(regexp, replacement [, target])

Search target for all of the longest, leftmost, nonoverlapping matching
substrings it can find and replace them with replacement. The ‘g’ in gsub()
stands for “global,” which means replace everywhere. For example:

{ gsub(/Britain/, "United Kingdom"); print }

replaces all occurrences of the string ‘Britain’ with ‘United Kingdom’ for
all input records.

The gsub() function returns the number of substitutions made. If the
variable to search and alter (target) is omitted, then the entire input
record ($0) is used. As in sub(), the characters ‘&’ and ‘\’ are special,
and the third argument must be assignable.
...

match(string, regexp [, array])

Search string for the longest, leftmost substring matched by the regular
expression regexp and return the character position (index) at which that
substring begins (one, if it starts at the beginning of string). If no
match is found, return zero.

The regexp argument may be either a regexp constant (/…/) or a string
constant ("…"). In the latter case, the string is treated as a regexp to be
matched. See Computed Regexps for a discussion of the difference between
the two forms, and the implications for writing your program correctly.

The order of the first two arguments is the opposite of most other string
functions that work with regular expressions, such as sub() and gsub(). It
might help to remember that for match(), the order is the same as for the
‘~’ operator: ‘string ~ regexp’.

The match() function sets the predefined variable RSTART to the index. It
also sets the predefined variable RLENGTH to the length in characters of
the matched substring. If no match is found, RSTART is set to zero, and
RLENGTH to -1.
...

sub(regexp, replacement [, target])

Search target, which is treated as a string, for the leftmost, longest
substring matched by the regular expression regexp. Modify the entire
string by replacing the matched text with replacement. The modified string
becomes the new value of target. Return the number of substitutions made
(zero or one).

The regexp argument may be either a regexp constant (/…/) or a string
constant ("…"). In the latter case, the string is treated as a regexp to be
matched. See Computed Regexps for a discussion of the difference between
the two forms, and the implications for writing your program correctly.

This function is peculiar because target is not simply used to compute a
value, and not just any expression will do—it must be a variable, field, or
array element so that sub() can store a modified value there. If this
argument is omitted, then the default is to use and alter $0.
...
[/quote]
--
"Irrigation of the land with seawater desalinated by fusion power is
ancient. It's called 'rain'." -- Michael McClary, in alt.fusion

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bob Bridges
2017-03-16 14:58:27 UTC
Permalink
Raw Message
I'd heard of regular expressions for years but used them only in a few exotic cases (in VBA), painfully. Then I went through a tumultuous 2½ years with a client who hired me as a TSS jock but ended up using me 85% as a VBA/Excel programmer, and I became an enthusiast; now I use regular expressions in VBA at the drop of a hat.

I'd use them in REXX, too, but they're not going to change the definition of REXX; someone would have to take the trouble to write them as an add-on. And come to think of it, haven't I heard that someone already has? But that would mean pretty limited exposure; only a few installations would have it, so you couldn't use and port them widely.

---
Bob Bridges
***@gmail.com, cell 336 382-7313
***@InfoSecInc.com

/* In its state of nature [a dog] has a smell, and habits, which frustrate man's love; he washes it, house-trains it, teaches it not to steal, and is so enabled to love it completely. To the puppy, the whole proceeding would seem, if it were a theologian, to cast grave doubts on the "goodness" of man; but the full-grown and full-trained dog, larger, healthier and longer-lived than the wild dog, and admitted, as it were by Grace, to a whole world of affections, loyalties, interests and comforts entirely beyond its animal destiny, would have no such doubt. -C S Lewis, _The Problem of Pain_ */


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of John McKown
Sent: Thursday, March 16, 2017 08:39

I hope people are not too upset with me for discussing some enhancements in REXX that I would like, which are mainly UNIX inspired. They should be made functional in "regular" REXX as well, not like the UNIX shell only functions such as lineout().

Regular expressions. Something akin to awk's match(), gsub(), and sub() functions.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Loading...