[removed] Extract MAC codes from freeform text using Regex

前端 未结 2 538
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 08:51

I\'m attempting to write a Chrome Extension that will scan a web page for valid MAC codes and push each in to an array. I have a regex that validates the MAC but I can\'t get it

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-25 09:28

    Remove the beginning of string ^ and end of string $ anchors and use the g (global) modifier..

    var regex = /([0-9A-F]{2}[:-]){5}([0-9A-F]{2})/g
    

    As stated in the documentation...

    The g modifier is used to perform a global match (find all matches rather than stopping after the first match)

提交回复
热议问题