1

So I made a vbs script for SecureCRT but it is not working. The script should look inside a text and check all interfaces then loop through them by issuing a command for each interface. the error I receive is in code line (Set matches = re.Execute(allthetext)) it is saying (Unexpected quantifier).

I hope to find a solotion

$language = "VBScript"
$interface = "1.0"

crt.Screen.Synchronous = True

Sub Main ()

    allthetext = "ge-10/1/2 but not ae22 and as well ge-1/0/0 in addtion xe-0/0/0:2, lets see"
    Set re = New RegExp
    re.Pattern = "\b{2}-\d{1,3}-\d{1,3}-\d{1,3}:\d|\b{2}-\d{1,3}-\d{1,3}-\d{1,3}"
    Set matches = re.Execute(allthetext)
    For Each match In matches
    theInterface = match.SubMatches(0)
    crt.Screen.Send "show interfaces " & theInterface & "| match ""down"" " & chr(13)
    Next
    
End Sub
user692942
  • 16,398
  • 7
  • 76
  • 175
A.D usa
  • 69
  • 5
  • This is a regular expression problem, have added the tag to the question. – user692942 Oct 01 '22 at 08:14
  • 1
    Yes I think it is a regex issue but not sure what is causing it. As for the main, no need need to call it as other scripts don't require it and they are working fine. – A.D usa Oct 01 '22 at 08:46
  • I corrected the regex now. It should be (re.pattern = "\w{2}-\d{1,3}\/\w{2}-\d{1,3}\/\w{2}-\d{1,3}" ) .... but I get the error (Invalid procedure call or argument) for the line ( theInterface = match.SubMatches(0)) – A.D usa Oct 01 '22 at 09:03

1 Answers1

1

The pattern does not work due to this part \b{2} where there is a quantifier for a word boundary that does not work.

You could either write the pattern as this, but note that there should be a word character before the starting -

\b-\d{1,3}-\d{1,3}-\d{1,3}:\d|\b-\d{1,3}-\d{1,3}-\d{1,3}

As there is some overlap in the pattern for the dash and digits part, you can rewrite it to this with an optional part for : and digit at the end using an optional group (?::\d)?

\b-\d{1,3}-\d{1,3}-\d{1,3}(?::\d)?

See a regex demo for the matches.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70