npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arktype/regex

v0.0.5

Published

A drop-in replacement for new RegExp() with types

Downloads

15

Readme

arkregex

A drop-in replacement for new RegExp() with types

Usage

The regex function creates a Regex instance with types for .test(), .exec() and more, statically parsed from native JS syntax:

import { regex } from "arkregex"

const ok = regex("^ok$", "i")
// Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>

const semver = regex("^(\\d*)\\.(\\d*)\\.(\\d*)$")
// Regex<`${number}.${number}.${number}`, { captures: [`${number}`, `${number}`, `${number}`] }>

const email = regex("^(?<name>\\w+)@(?<domain>\\w+\\.\\w+)$")
// Regex<`${string}@${string}.${string}`, { names: { name: string; domain: `${string}.${string}`; }; ...>

All you need to get started is pnpm install arkregex (or the equivalent for your package manager of choice) 🎉

Performs best with TS 5.9+

Features

  • Types: Infers string types for your existing regular expressions, including positional and named captures
  • Parity: Supports 100% of features allowed by new RegExp()
  • Safety: Syntax errors like referencing a group that doesn't exist are now type errors
  • Zero Runtime: Improves your type safety without impacting your bundle size

FAQ

Why aren't some patterns like [a-Z] inferred more precisely?

Constructing string literal types for these sorts of expressions is combinatorial and will explode very quickly if we infer character ranges like this as literal characters.

We've tried to strike a balance between performance and precision while guaranteeing that the inferred types are at worst imprecise and never incorrect.

Why doesn't it work with my massive RegExp?

If your expression is especially long or complex, TypeScript won't be able to infer it.

If your types start to slow down or you see the dreaded Type is excessively deep..., you can manually type your expression using regex.as:

const complexPattern = regex.as<`pattern-${string}`, { captures: [string] }>(
	"very-long-complex-expression-here"
)

Is it robust?

arkregex types are extensively tested and benchmarked using attest.

If anything not covered by the other FAQs is not behaving how you'd expect, please don't hesitate to create an issue.

How can I get syntax highlighting for regex?

The ArkType extension can be installed to add syntax highlighting to regex calls.