Networkingflags: g

FTP URL

Match FTP and FTPS URLs, capturing optional credentials, host, port, and path.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
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).

Pattern

regexengine-agnostic
ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)?   (flags: g)

Raw source: ftps?:\/\/(?:([^:@\s]+)(?::([^@\s]*))?@)?([^:\/\s]+)(?::(\d+))?(?:\/\S*)?

How it works

ftps?:\/\/ matches both `ftp://` and `ftps://`. The optional auth group captures user and password. The host group captures the server. (?::(\d+))? optionally captures the port (default is 21). (?:\/\S*)? optionally captures the path.

Examples

Input

Source: ftp://anon:guest@files.example.com/pub/data.csv

Matches

  • ftp://anon:guest@files.example.com/pub/data.csv

Input

ftps://secure.host:990/private

Matches

  • ftps://secure.host:990/private

Input

no ftp link

No 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