How to correct SecureCRT vbs Regex

334 views Asked by At

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
1

There are 1 answers

0
The fourth bird On BEST ANSWER

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.