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

to-regex-range

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-regex-range

Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
71M
increased by19.13%
Maintainers
2
Weekly downloads
 
Created

What is to-regex-range?

The to-regex-range npm package is designed to generate regular expressions for matching numeric ranges. It is useful for creating regex patterns that can match against specific ranges of numbers, allowing for precise control over numeric input validation, among other applications.

What are to-regex-range's main functionalities?

Generating regex for simple numeric ranges

This feature allows you to generate a regex pattern for a simple numeric range, such as from 5 to 10. The resulting regex will match any number within this range.

const toRegexRange = require('to-regex-range');
const regex = toRegexRange('5', '10');
console.log(regex); // => '5|6|7|8|9|10'

Creating regex with zero-padding

This feature enables the generation of regex patterns that account for zero-padded numbers, useful for matching numbers within a range where the number of digits is consistent.

const toRegexRange = require('to-regex-range');
const regex = toRegexRange('001', '100', { capture: true, pad: true });
console.log(regex); // Example output: '(0[0-9]{2}|1[0-9]{2})'

Generating regex for complex ranges with options

This feature allows for the creation of regex patterns for more complex numeric ranges with additional options, such as disabling the relaxation of leading zeros, providing more precise control over the matching behavior.

const toRegexRange = require('to-regex-range');
const regex = toRegexRange('10', '299', { relaxZeros: false });
console.log(regex); // Example output: '1[0-9]|2[0-9]{2}'
0

Keywords

FAQs

Package last updated on 01 Nov 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