Python Package Name (PEP 508)
Validate Python distribution package names per PEP 508: letters, digits, dots, underscores, hyphens.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9._\\-]*[A-Za-z0-9])?$", "");
const input = "requests";
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-Za-z0-9](?:[A-Za-z0-9._\-]*[A-Za-z0-9])?$")
input_text = "requests"
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-Za-z0-9](?:[A-Za-z0-9._\-]*[A-Za-z0-9])?$`)
input := `requests`
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-Za-z0-9](?:[A-Za-z0-9._\-]*[A-Za-z0-9])?$Raw source: ^[A-Za-z0-9](?:[A-Za-z0-9._\-]*[A-Za-z0-9])?$
How it works
Examples
Input
requestsMatches
requests
Input
django-rest-frameworkMatches
django-rest-framework
Input
_invalidNo match
—Common use cases
- •pip / poetry / uv config validation
- •PyPI package-name availability checks
- •Migration tooling between requirements formats
- •Auto-completion in package managers
Related patterns
npm Package Name
IdentifiersValidate npm package names including scoped packages (@org/package), per the npm naming spec.
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.
AWS ARN (Amazon Resource Name)
IdentifiersMatch AWS ARNs (Amazon Resource Names) across commercial, China, and GovCloud partitions.