npm Package Name
Validate npm package names including scoped packages (@org/package), per the npm naming spec.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^(?:@[a-z0-9\\-*~][a-z0-9\\-*._~]*\\/)?[a-z0-9\\-~][a-z0-9\\-._~]*$", "");
const input = "react";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$")
input_text = "react"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$`)
input := `react`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$Raw source: ^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$
How it works
Examples
Input
reactMatches
react
Input
@types/nodeMatches
@types/node
Input
MyPackageNo match
—Common use cases
- •package.json validation in monorepo tooling
- •Custom registry name enforcement
- •Automated dependency auditing scripts
- •CLI tools that accept package names as arguments
Related patterns
Python Package Name (PEP 508)
IdentifiersValidate Python distribution package names per PEP 508: letters, digits, dots, underscores, hyphens.
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Kubernetes Pod Name (RFC 1123)
IdentifiersValidate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
Kubernetes Label (key=value)
IdentifiersValidate Kubernetes label `key=value` pairs per the K8s naming spec.