URL Path Segments

Split a hierarchical absolute URL path into percent-encoded segments while preserving empty interior and trailing segments.

Description

Slash-delimited URL paths can contain empty segments, which may matter to routing.

Slash-delimited URL paths can contain empty segments, which may matter to routing. A percent-encoded slash remains part of a segment rather than becoming a separator.1

Split a hierarchical absolute URL path into percent-encoded segments while preserving empty interior and trailing segments.

When to use URL Path Segments

Use this tool to split a hierarchical absolute URL path into percent-encoded segments while preserving empty interior and trailing segments.

Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.

How to use URL Path Segments and understand its results

  1. Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.
  2. Enter url using the field table and calculation rules, then run the tool.
  3. Read segments. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
urlAbsolute hierarchical URL.string; maximum length: 1000000Required

Enter an absolute URL whose parsed pathname starts with a slash. The tool removes exactly that initial slash and splits the normalized path, preserving empty interior and trailing segments. The root slash produces one empty segment. Paths without a leading slash are rejected as opaque.

segments=normalizedPathname.slice(1).split('/')

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
segmentsPath segments without the initial slash.list of string; maximum length: 1000000; minimum entries: 0; maximum entries: 100000
json
{
  "input": {
    "url": "https://example.com/a//b%20c/"
  },
  "output": {
    "segments": [
      "a",
      "",
      "b%20c",
      ""
    ]
  }
}

Limitations and assumptions

Segments retain percent escapes. This does not resolve routes or decode names, and parsing can already remove dot segments before splitting.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use URL Pathname: Extract the pathname of an absolute URL using the WHATWG URL parser, including its normalization rules. For a complementary task, use URL Is Absolute: Check whether a reference parses as an absolute WHATWG URL.

References

  1. URL Path Segments — tool.io

Similar or alternative tools

  • URL Pathname

    Extract the pathname of an absolute URL using the WHATWG URL parser, including its normalization rules.

  • URL Is Absolute

    Check whether a reference parses as an absolute WHATWG URL.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies