Crates.io | rexturl |
lib.rs | rexturl |
version | |
source | src |
created_at | 2022-09-16 13:09:55.671937+00 |
updated_at | 2025-03-23 08:43:45.860277+00 |
description | A simple tool to split urls in their protocol, host, port, path and query parts. |
homepage | https://github.com/vschwaberow/rexturl.git |
repository | https://github.com/vschwaberow/rexturl.git |
max_upload_size | |
id | 667341 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A versatile command-line tool for parsing and manipulating URLs.
cargo install rexturl
or clone the repository and build from source:
git clone https://github.com/vschwaberow/rexturl.git
cd rexturl
cargo build --release
rexturl [OPTIONS] [URLS...]
If no URLs are provided, rexturl will read from stdin.
--urls <URLS>
Input URLs to process
--scheme
Extract and display the URL scheme
--username
Extract and display the username from the URL
--host
Extract and display the hostname
--port
Extract and display the port number
--path
Extract and display the URL path
--query
Extract and display the query string
--fragment
Extract and display the URL fragment
--sort
Sort the output
--unique
Remove duplicate entries from the output
--json
Output results in JSON format
--all
Display all URL components
--custom
Enable custom output mode
--domain
Extract the domain
--format <FORMAT>
Custom output format (default: "{scheme}://{host}{path}")
-h
, --help
Print help information
-V
, --version
Print version information
Extract all components from a single URL:
rexturl --all https://user:pass@example.com:8080/path?query=value#fragment
Extract host and port from multiple URLs:
rexturl --host --port https://example.com https://api.example.com:8443
Process URLs from a file, extracting paths and sorting results:
cat urls.txt | rexturl --path --sort
Use custom output format:
rexturl --custom --format "{scheme}://{host}:{port}{path}" https://example.com:8080/api
Output results in JSON format:
rexturl --json --all https://example.com https://api.example.com
Sort and deduplicate results:
echo -e "https://example.com\nhttps://example.com\nhttps://api.example.com" | rexturl --host --sort --unique
rexturl
includes special handling for domains and subdomains:
--domain
flag extracts the domain name from the URL, with proper handling of multi-part TLDs--host
alone (without other component flags), it extracts the subdomain by defaultExamples:
# Extract domain from a URL with multi-part TLD
echo "https://blog.example.co.uk/posts" | rexturl --domain
# Output: example.co.uk
# Extract subdomain from a URL
echo "https://blog.example.co.uk/posts" | rexturl --host
# Output: blog
# Extract subdomain and domain separately using custom format
echo "https://blog.example.co.uk/posts" | rexturl --custom --format "Subdomain: {subdomain}, Domain: {domain}"
# Output: Subdomain: blog, Domain: example.co.uk
When using --custom
and --format
, you can use the following placeholders:
{scheme}
- URL scheme (http, https, etc.){username}
- Username portion of the URL{host}
- Full hostname{hostname}
- Alias for host{subdomain}
- Subdomain portion (e.g., "www" in www.example.com){domain}
- Domain name (e.g., "example.com"){port}
- Port number{path}
- URL path{query}
- Query string (without the leading ?){fragment}
- Fragment identifier (without the leading #)Example:
rexturl --custom --format "Host: {host}, Path: {path}" https://example.com/api
rexturl --custom --format "Subdomain: {subdomain}, Domain: {domain}" https://blog.example.co.uk/posts
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.