Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cidr-regex

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cidr-regex

Regular expression for matching IP addresses in CIDR notation

  • 2.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
786K
increased by0.51%
Maintainers
2
Weekly downloads
 
Created

What is cidr-regex?

The 'cidr-regex' npm package provides regular expressions for matching and validating CIDR (Classless Inter-Domain Routing) notation IP addresses, both IPv4 and IPv6. This is useful for network configuration, validation, and parsing tasks.

What are cidr-regex's main functionalities?

Match CIDR Notation

This feature allows you to check if a given string matches the CIDR notation for IPv4 or IPv6 addresses.

const cidrRegex = require('cidr-regex');

const ip = '192.168.0.1/24';
const isMatch = cidrRegex().test(ip);
console.log(isMatch); // true

Extract CIDR Notation

This feature allows you to extract all CIDR notations from a given string.

const cidrRegex = require('cidr-regex');

const text = 'Here is a CIDR: 192.168.0.1/24 and another one: 10.0.0.0/8';
const matches = text.match(cidrRegex());
console.log(matches); // ['192.168.0.1/24', '10.0.0.0/8']

IPv4 and IPv6 Support

This feature provides separate methods for matching IPv4 and IPv6 CIDR notations.

const cidrRegex = require('cidr-regex');

const ipv4 = '192.168.0.1/24';
const ipv6 = '2001:db8::/32';
console.log(cidrRegex.v4().test(ipv4)); // true
console.log(cidrRegex.v6().test(ipv6)); // true

Other packages similar to cidr-regex

Keywords

FAQs

Package last updated on 18 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc