const regex = new RegExp('(?P<type>SLA)(?:::)(?P<sa>[0-9]{4,7}|(?:_))?(?:::)(?P<cid>[a-zA-Z-0-9-/._]{8,}|(?:_))?(?:::)(?P<ip>\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|(?:_))?(?:::)(?P<desc>[\\w#()/-]*)', 'gm')
const str = `SLA::3223453::801-4259::10.224.0.88::PIONEERLAND_DASSEL
SLA::3223482::_::_::PIONEERLAND_RAYMOND
UNI::3238811::ROCHESTER_COMMUNITY_COLLEGE
SLA::_::_::10.224.0.88::PIONEERLAND_WILLMAR_DC
SLA::3211691::A1Q0041C::_::TMOBILE_511_PARK_AVE
SLA::3206176::EEVC/011439//2636/EPL::10.252.51.50::CHARTER_BANK
SLA::3206176::_::10.252.51.50::CHARTER_BANK
SLA::3223621::70.VLXP.024011..CBCL..::_::GOEBEL_FIXTURES_COMPANY
SLA::3178253::KRE1/50393/MPT/CTTNMNTMOB1::10.224.0.88::TMOBILE_COTTON
ACCESS::DSLAM_TEST
SLA::3265812::L2XN/77798/MPT/LRTOMNARPF::10.224.0.159::CCI_ARROWHEAD_PROMOTION
SLA::3152953::180-361-0266::10.252.51.101::HORMEL_BLOOMING_PRAIRIE
SLA::3137605::GEYX/065858::10.252.2.203::ZAYO_VZW_KIMBALL
SLA::3171637::88/INFR/102977//DCE/::10.252.2.25::BNC_BANK
SLA::3182788::150-368-0293::10.252.51.36::NORTHFIELD-HOSPITAL
SLA::3221907::EVENT_41767_PEARL_LAKE_LIT::10.224.0.166::VZW_PEARLLAKE
SLA::_::_::_::VZW_GP_RED_WING_WEST
SLA::3227386::16-KFLA-01156--NVP::_::ZAYO_DULUTH_GROUP`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions