Webflags: g
URL Path Segment
Match individual `/segment` parts of a URL path, capturing each one.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
\/([^\/?#\s]+) (flags: g)Raw source: \/([^\/?#\s]+)
How it works
\/ matches the literal slash. ([^\/?#\s]+) captures one or more characters that aren't a slash, question mark, hash, or whitespace — i.e. one path segment. Useful for breaking apart a URL into its component pieces.
Examples
Input
/users/42/posts?page=2Matches
/users/42/posts
Input
/api/v1/healthMatches
/api/v1/health
Input
no/pathNo match
—Common use cases
- •Routing-table introspection
- •URL normalization / rewriting
- •Analytics: per-path-segment aggregation
- •API gateway pattern matching
Related patterns
OpenAPI Path Template
WebMatch OpenAPI / Express-style path templates with `{param}` (or `:param` after substitution) placeholders.
Twitter / X URL
WebMatch Twitter/X profile and status URLs, capturing the handle and (optional) tweet ID.
URL Query String
WebExtract the query string portion of a URL (everything between `?` and `#` or end-of-string).
URL Slug
WebValidate URL slugs: lowercase letters and digits separated by single hyphens, no leading/trailing hyphens.