RegularExpression
Posted: Mon Mar 06, 2023 10:35 am
Hi guys,
i am in the process of extending an older PB program. Since some time PB supports "RegularExpression". I think that these 2 routines can be replaced by this one. I have never dealt with "RegularExpression" before and the sample code in the PB reference is more than poor. I know there is ext.literature about it, but I don't have the inclination or time to go that deep into it. Can someone rewrite the code below for me in RegularExpression?
i am in the process of extending an older PB program. Since some time PB supports "RegularExpression". I think that these 2 routines can be replaced by this one. I have never dealt with "RegularExpression" before and the sample code in the PB reference is more than poor. I know there is ext.literature about it, but I don't have the inclination or time to go that deep into it. Can someone rewrite the code below for me in RegularExpression?
Code: Select all
Procedure ValidChar(STRING$, VALIDCHAR$)
; Returns #True if no other Charakters were found in STRING$ that contain VALIDCHAR$
For a = 1 To Len(STRING$)
For b = 1 To Len(VALIDCHAR$)
If Mid(STRING$,a,1) = Mid(VALIDCHAR$,b,1)
Break
EndIf
Next
If Mid(STRING$,a,1) <> Mid(VALIDCHAR$,b,1)
ProcedureReturn #False
EndIf
Next
ProcedureReturn #True
EndProcedure
Procedure InValidChar(STRING$, INVALIDCHAR$)
; Returns #True if STRING$ contains a character from INVALIDCHAR$
For a = 1 To Len(STRING$)
For b = 1 To Len(INVALIDCHAR$)
If Mid(STRING$,a,1) = Mid(INVALIDCHAR$,b,1)
ProcedureReturn #True
EndIf
Next
Next
ProcedureReturn #False
EndProcedure
ValidChars$ =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Debug ValidChar("test1", ValidChars$)
Debug ValidChar("test1_", ValidChars$)
InValidChars$ =";,:._-()/&%"
Debug InValidChar("test1", InValidChars$)
Debug InValidChar("test1_", InValidChars$)