Here is a copy of my Filter routine along with 2 examples.
I think I posted this once before.
/* REXX */
/* Example one: Does the string match the mask? */
mask1 = 'XX.Y*Y.**.*ZZZ'
mask2 = 'XX.Y%%Y.**.*ZZZ'
string1 = 'XX.Y1R2T3Y.ZYX.D53ZZZ'
string2 = 'XX.Y1R2T3.ZYX.D53ZZZ'
string3 = 'XX.Y12Y.ZYX.D53ZZZ'
string4 = 'XX.Y123Y.ZYX.D53ZZZ'
say '('string1') ('mask1')'
If Filter(string1,mask1) then say 'YES'; else say 'No, only upto' EndStr
say '('string2') ('mask1')'
If Filter(string2,mask1) then say 'YES'; else say 'No, only upto' EndStr
say '('string1') ('mask2')'
If Filter(string3,mask2) then say 'YES'; else say 'No, only upto' EndStr
say '('string2') ('mask2')'
If Filter(string4,mask2) then say 'YES'; else say 'No, only upto' EndStr
/* Example two: does string contain mask? */
String = 'The quick brown fox jumps over the lazy dog'
ruler = '1...5....0....5....0....5....0....5....0...4'
Mask.1 = '%%E%%%%%%%BROWN'
Mask.2 = '*QUICK*F%X'
Mask.3 = '*t '
Mask.4 = 'THE%Q%*%**BR%%%'
Mask.5 = ' E*BROWN'
Mask.6 = '*THE*BRXWN'
Mask.7 = '*THE*BROWN**F%%'
Mask.8 = '*FOX*'
Mask.9 = '*F%X*'
Mask.10= '*F%*%MP*G'
Mask.11= 'T*E LAZY DOG'
Mask.12= '*E LAZY DOG'
Mask.13= '* JU'
Mask.14= '*O%E'
Mask.15= '%*V*D'
Mask.16= '*G*'
Mask.17= '*G%'
Mask.18= '-*7'
say string
say ruler
Do m = 1 to 18
If Filter(string,mask.m,1) & left(mask.m,1) <> '-' then
Status = 'Found ',
right(BgnStr,3) Right(EndStr,3),
substr(string,BgnStr,EndStr+1-BgnStr)
else Status = 'NOT Found' z
say left(Mask.m,25) Status
End
Exit 0
/*-----------------------------The Filter----------------------------*/
Filter:
Arg stringx,maskx,strt
/* Adjust mask: */
/* if there is an * in a set of wild characters it should be */
/* the last char in the set ie %%*%**%% s/b %%%%%* */
/* only one * is needed within each set of wild characters */
/* an ending * is not needed */
/* To find a match anywhere within the string, */
/* put an * at the begining of the mask */
/* To return "true" if the string does not match the mask, */
/* put a - at the begining of the mask */
/* mask = '-*X' returns true if X not in string */
If maskx = '' then Return 1
RtnCd0 = 0; RtnCd1 = 1
If left(maskx,1) = '-' then Do
maskx = substr(maskx,2)
RtnCd0 = 1; RtnCd1 = 0
End
Do while pos('*%',maskx) > 0
maskx = overlay('%*',maskx,pos('*%',maskx))
End
Do while pos('**',maskx) > 0
maskx = delstr(maskx,pos('**',maskx),1)
End
maskx = strip(maskx,'T','*')
LenMask = length(maskx)
If LenMask = 0 then Return RtnCd1
If datatype(strt) <> "NUM" then strt = 1
If strt < 1 | strt > length(stringx) then strt = 1
Nxtj = strt-1 /* The next position (-1) of the string to check */
Nxti = 1 /* The next position of the mask to match */
BgnStr = 0
EndStr = 0
Savei = Nxti /* save where we are in mask and string */
Savej = Nxtj
SaveBgnStr = 0
NoAst = 1
Do z = 1 to length(stringx) /* z = number of iterations */
i = Nxti
j = Nxtj
Do while j < length(stringx)
j = j+1
Select
when substr(maskx,i,1) = '*' then Do
Savei = i /* save where we are in mask and string */
Savej = j
SaveBgnStr = BgnStr
NoAst = 0
/* look for mask/string match after an *, */
/* if found set pointers to continue looking */
If substr(maskx,i+1,1) == substr(stringx,j,1) then Do
i=i+1
j=j-1
End
End
when substr(maskx,i,1) = '%' |,
substr(maskx,i,1) == substr(stringx,j,1) then Do
If BgnStr = 0 then BgnStr = j
EndStr = j
i=i+1
If i > LenMask then Return RtnCd1
End
/* mismatch, go back to last * and look again */
otherwise Do
If NoAst then Return RtnCd0
BgnStr = SaveBgnStr
Nxti = Savei
Nxtj = Savej
iterate z
End
End
End
Return RtnCd0
End
Return RtnCd0
/* */
-----Original Message-----
From: TSO REXX Discussion List [mailto:
TSO-...@VM.MARIST.EDU] On Behalf Of Steve Coalbran