FTP URL
Match FTP and FTPS URLs, capturing optional credentials, host, port, and path.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("ftps?:\\/\\/(?:([^:@\\s]+)(?::([^@\\s]*))?@)?([^:\\/\\s]+)(?::(\\d+))?(?:\\/\\S*)?", "g");
const input = "Source: ftp://anon:guest@files.example.com/pub/data.csv";
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"ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)?")
input_text = "Source: ftp://anon:guest@files.example.com/pub/data.csv"
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(`ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)?`)
input := `Source: ftp://anon:guest@files.example.com/pub/data.csv`
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
ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)? (flags: g)Raw source: ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)?
How it works
Examples
Input
Source: ftp://anon:guest@files.example.com/pub/data.csvMatches
ftp://anon:guest@files.example.com/pub/data.csv
Input
ftps://secure.host:990/privateMatches
ftps://secure.host:990/private
Input
no ftp linkNo match
—Common use cases
- •Legacy data-pipeline ingestion
- •Mainframe / EDI integration tooling
- •Credentials auditing in log files
- •Migrating FTP links to S3 / SFTP equivalents
Related patterns
Redis Connection URL
NetworkingMatch Redis connection URLs in both `redis://` and `rediss://` (TLS) forms, capturing user, password, host, port, and DB index.
JDBC Connection URL
NetworkingMatch JDBC connection URLs in the standard `jdbc:driver://host[:port][/database]` form.
Generic Connection String (URL Form)
NetworkingParse generic URL-form connection strings: `protocol://[user[:pass]@]host[:port][/database]`.
TCP/UDP Port Number
NetworkingMatch port numbers (1–65535) following a colon, as you'd find in host:port strings.