
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
strings-to-regex
Advanced tools
Generate a compact Regular Expression that matches a finite set.
Have you ever seen a dense Regular Expression like this one to match the 50 US state abbreviations?
/(A(L|K|Z|R)|C(A|O|T)|DE|FL|GA|HI|I(D|L|N|A)|K(S|Y)|LA|M(E|D|A|I|N|S|O|T)|N(E|V|H|J|M|Y|C|D)|O(H|K|R)|PA|RI|S(C|D)|T(N|X)|UT|V(T|A)|W(A|V|I|Y))/
This library generates patterns like that to match a list of strings you provide.
To reverse this process and list which strings a Regular Expression would match, try regex-to-strings
.
condense(arrayOfStrings)
Generate a Regular Expression to match all strings in arrayOfStrings
. Respects the casing of the strings. Returns a RegExp
object.
import { condense } from 'strings-to-regex';
const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz'];
const matcher = condense(stringsToMatch);
console.log(matcher); // /(foo(|bar|BarBaz)|Foo)/
condenseIgnoreCase(arrayOfStrings)
A variation of condense()
that ignores the casing of the strings. Returns a RegExp
object.
import { condenseIgnoreCase } from 'strings-to-regex';
const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz'];
const matcher = condenseIgnoreCase(stringsToMatch);
console.log(matcher); // /foo(|bar(|baz))/i
FAQs
Condense a set of words into a regular expression pattern
The npm package strings-to-regex receives a total of 422 weekly downloads. As such, strings-to-regex popularity was classified as not popular.
We found that strings-to-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.