|
Answer» I have a config file that passes Parameters to a VBscript, in this VBscript I want to confirm that the Parameter is correct.
Parameter could look something LIKE this. P 2%r XXX without the spaces
P is a value that can be any letter a-z upper or lowercase
2%r should always stay the same
and XXX can be any letter a-z upper or lowercase and any number.
RegExp [a-zA-Z][%][2][r][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]
[a-zA-Z] - This part seems to be BROKEN in that if the user miskeys the config Ppp or PP will still be acceptable and I only need a Single letter to be acceptable
I think [%][2][r] is ok, but tweak if you KNOW a better way.
I am thinking I have the same problem with this piece [a-zA-Z0-9] as {3} grouping doesn't seem to be working. I am not testing in VBscript and maybe that is my issue. I am testing in UltraEdit which ALLOWS you to use regular expressions for searching.
Any and all help is appreciated. Thanks. Code: [Select]Dim regEx strWords = "P2%rXXX" Set regEx = New RegExp regEx.Pattern = "^[a-z]2%r[a-z0-9]{3}$" regEx.IgnoreCase = True Set colMatches = regEx.Execute(strWords) WScript.Echo vbNewLine & "Resulting Matches:" For Each objMatch In colMatches WScript.Echo "At position " & objMatch.FirstIndex & " matched " & objMatch.Value Next Thanks that seems to work.
Being REALLY new to the whole VBS world would you be able to elaborate as far as far as using the Boolean (True, False) to return to the primary Function 0 it matches 1 it failed exit.
Thanks again for any and all help.Woot! looks like I got it to work. Thanks for the assistance
strWords = GetFileMask Set regEx = New RegExp regEx.Pattern = "^[a-z]%2r[a-z0-9]{3}$" regEx.IgnoreCase = True ExpressionMatch = regEx.TEST(strWords)
If ExpressionMatch Then '''WScript.echo regEx.Pattern & " was found in " & strWords CheckMflag = 0 Else '''WScript.echo regEx.Pattern & " was not found in " & strWords CheckMflag = 1 End If
|