Socket
Socket
Sign inDemoInstall

regex-test

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    regex-test

Safely test strings against any regex with a timeout.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
343 kB
Created
Weekly downloads
 

Readme

Source

regex-test

Safely test strings against any regex with a timeout.

Installation

npm:

npm install regex-test

yarn:

yarn add regex-test

GitHub:

git clone https://github.com/venomaze/regex-test.git

Usage

First create a new instance:

const RegexTest = require('regex-test');

const regex = new RegexTest({
  timeout: 500, // ms
  safeRegexOnly: true,
});

Then you can use the test method this way:

const pattern = /^([a-zA-Z0-9])(([\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$/;

regex
  .test(pattern, 'test@mail.com')
  .then(res => console.log(res))
  .catch(err => console.log(err.message));

regex
  .test(pattern, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!')
  .then(res => console.log(res))
  .catch(err => console.log(err.message));

Options

The options are:

  • timeout: The timeout for regular expression tests in milliseconds. (Default to 1000)
  • safeRegexOnly: If true, throw an error if the regex is a potentially catastrophic exponential-time regular expression. (Default to false)

Keywords

FAQs

Last updated on 20 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc