Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-25-2014, 09:37 AM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
Try to match multiple Mac addresses

I try to use below RegEx pattern and Script to match all the mac addresses , but every time the script only match the First Mac address, it doesn't not match the Second Mac address.

Macs.count (see below) is always 1.


Code:
Source Data:
160k1flSW81#sh mac add int g1/0/2
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
  54    1803.733b.f4fb    STATIC      Gi1/0/2 
 380    001e.f729.8626    STATIC     Gi1/0/2 
Total Mac Addresses for this criterion: 2

Code:
Set MMC = New RegExp
MMC.Pattern = "\d+\s+([0-9a-f]{4}\.[0-9a-f]{4}\.[0-9a-f]{4})\s+\S+\s+\S+"  
MMC.IgnoreCase = True

strResultsMac = crt.Screen.ReadString("#")

If MMC.Test(strResultsMac) <> True Then
   ws.Cells(row, 3).Value = "No Mac detected" 

Else
    
    Set Macs = MMC.Execute(strResultsMac) 
    MsgBox "Macs.count=" & Macs.count

    Temp = ""				
    
    For Each Mac In Macs
        Temp = Temp & Mac.SubMatches(0) & Chr(10)
    Next

ws.Cells(row, 3).Value = Temp   --> only see just "1" Mac address

Last edited by mybox65; 04-25-2014 at 10:04 AM.
Reply With Quote
  #2  
Old 04-25-2014, 10:05 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,085
Quote:
Originally Posted by mybox65 View Post
I try to use below RegEx pattern and Script to match all the mac addresses , but every time the script only match the First Mac address, it doesn't not match the Second Mac address.
What you haven't done yet is instruct the RegExp object that you'd like to know about all the matches, not just the first one.

See the attached screenshot of Microsoft's VBScript help manual for information on how to set the Global property of the RegExp object to True so it will return all matches found.

If there are other questions about VBScript natives, Microsoft's VBScript help can be downloaded and installed locally to your machine, and is a good resource you can use to find answers.

--Jake
Attached Images
File Type: png Script56Help-RegExpGlobalProperty.png (75.1 KB, 273 views)
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 04-25-2014, 10:14 AM
mybox65 mybox65 is offline
Registered User
 
Join Date: Feb 2012
Posts: 17
Quote:
Originally Posted by jdev View Post
What you haven't done yet is instruct the RegExp object that you'd like to know about all the matches, not just the first one.

See the attached screenshot of Microsoft's VBScript help manual for information on how to set the Global property of the RegExp object to True so it will return all matches found.

If there are other questions about VBScript natives, Microsoft's VBScript help can be downloaded and installed locally to your machine, and is a good resource you can use to find answers.

--Jake

Hi Jake,

Thank you very much !!! I really like your team and product.

Regards,

Mybox
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:30 AM.