npm Package Name in PY
Validate npm package names including scoped packages (@org/package), per the npm naming spec.
Try it in the PY tester →Pattern
regexPY
^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$Python (re) code
pyPython
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+.
How the pattern works
The optional group (?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)? matches a @scope/ prefix for scoped packages. The main name [a-z0-9\-~][a-z0-9\-._~]* matches lowercase letters, digits, hyphens, dots, and tildes. Uppercase is not allowed per npm rules.
Examples
Input
reactMatches
react
Input
@types/nodeMatches
@types/node
Input
MyPackageNo match
—