---
title: "getUrlExtension"
description: "Extract the file extension from a URL pathname, returning the part after the last dot so you can branch on asset or document types."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-url-extension"
---
# getUrlExtension

> Extract the file extension from a URL pathname, returning the part after the last dot so you can branch on asset or document types.

## Usage

`getUrlExtension` extracts the file extension from a URL.

```ts
import { getUrlExtension } from '@movk/core'

getUrlExtension('https://example.com/file.pdf') // 'pdf'
getUrlExtension('https://example.com/file.tar.gz') // 'gz'
getUrlExtension('https://example.com/path/') // ''
```

## API

### `getUrlExtension(url)`

Get the file extension from a URL.

### Parameters

**url** (`string`) *required*: The URL string.

### Returns

**returns** (`string`): The file extension without the leading dot, or an empty string if none found.

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/parse.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
