const regex = /([^\n\r:]*)(:[ \t])[ \t]*([^\n\r]*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([^\\n\\r:]*)(:[ \\t])[ \\t]*([^\\n\\r]*)', 'gm')
const str = `NetRange: 2001:4860:: - 2001:4860:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
CIDR: 2001:4860::/32
NetName: GOOGLE-IPV6
NetHandle: NET6-2001-4860-1
Parent: ARIN-004 (NET6-2001-4800-0)
NetType: Direct Allocation
OriginAS: AS15169
Organization: Google LLC (GOGL)
RegDate: 2005-03-14
Updated: 2012-02-24
Ref: https://rdap.arin.net/registry/ip/2001:4860::
OrgName: Google LLC
OrgId: GOGL
Address: 1600 Amphitheatre Parkway
City: Mountain View
StateProv: CA
PostalCode: 94043
Country: US
RegDate: 2000-03-30
Updated: 2019-10-31
Comment: Please note that the recommended way to file abuse complaints are located in the following links.
Comment:
Comment: To report abuse and illegal activity: https://www.google.com/contact/
Comment:
Comment: For legal requests: http://support.google.com/legal
Comment:
Comment: Regards,
Comment: The Google Team
Ref: https://rdap.arin.net/registry/entity/GOGL
OrgTechHandle: ZG39-ARIN
OrgTechName: Google LLC
OrgTechPhone: +1-650-253-0000
OrgTechEmail: arin-contact@google.com
OrgTechRef: https://rdap.arin.net/registry/entity/ZG39-ARIN
OrgAbuseHandle: ABUSE5250-ARIN
OrgAbuseName: Abuse
OrgAbusePhone: +1-650-253-0000
OrgAbuseEmail: network-abuse@google.com
OrgAbuseRef: https://rdap.arin.net/registry/entity/ABUSE5250-ARIN
RNOCHandle: ZG39-ARIN
RNOCName: Google LLC
RNOCPhone: +1-650-253-0000
RNOCEmail: arin-contact@google.com
RNOCRef: https://rdap.arin.net/registry/entity/ZG39-ARIN
RTechHandle: ZG39-ARIN
RTechName: Google LLC
RTechPhone: +1-650-253-0000
RTechEmail: arin-contact@google.com
RTechRef: https://rdap.arin.net/registry/entity/ZG39-ARIN
RAbuseHandle: ZG39-ARIN
RAbuseName: Google LLC
RAbusePhone: +1-650-253-0000
RAbuseEmail: arin-contact@google.com
RAbuseRef: https://rdap.arin.net/registry/entity/ZG39-ARIN`;
// 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