Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REXX and Pattern Recognition (of other patterns)

Status
Not open for further replies.

lsman11

Programmer
Dec 22, 2004
18
US
Hello,

During a meeting, we were questioned about REXX's ability for pattern recognition. The straightforward question is, does REXX contain pattern recognition, that is powerful enough to compare two patterns against each other (which would be able to determine if one pattern is a SUBSET of the other)?

So given a str1, which wants to match on strings starting with an A and ending with a B: A*B (i suppose)

And given a str2, which wants to match on any string starting with A: A* (i suppose)

Can REXX inform me that filter str1 is a subset of filter str2? (both str1 and str2 are used to as pattern filters).

Any help appreciated. As you can see i am not a big REXX programmer, but was told that REXX may have this capability.

Thanks!
Luis
 

REXX's string-handling is prodigious, so the answer is probably 'yes'. There is nothing built-in, however, that is specifically targeted at 'pattern recognition'.


Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
I,

The POS command will let you find any character in a string, so yes you can program for any "A*" or "A*B" pattern.

Reference is at:


Your code should look something like this:

Ex 1:
/* REXX Pattern Find */
my_pat = "A*"
my_inp = "My Input Pattern String looking for A then anything"
fd_pat = left(trim(my_pat,1,1))
fd_wld = right(trim((my_pat,1))
fd_pos = pos(my_inp,fd_pat)
ot_pat = substr(my_inp,fd_pos)
say ot_pat

Will give you:

"A then anything"

Ex 2:
/* REXX Pattern Find */
my_pat = "A*B"
my_inp = "My Input Pattern String looking for A and anything to B and then some"
fd_pat = left(trim(my_pat,1,1))
fd_lst = right(trim((my_pat,1))
fd_wld = substr(my_pat,pos(my_pat,"*"),1)
fd_pos = pos(my_inp,fd_pat)
ls_pos = length(my_inp) - pos(reverse(my_inp),fd_lst)
ot_pat = substr(my_inp,fd_pos,ls_pos)
say ot_pat


Will give you:

"A then anything to B"

I did this without testing so you may have to tweak a little! To make it test for both coditions combine the two with some "if then" or "select" logic.

YMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top