DD
DevDash

Regex for FTP URL

Regex Pattern

^ftps?:\/\/[^\s/$.?#].[^\s]*$

FTP or FTPS URL

Quick Answer

The regex pattern for ftp url is `^ftps?:\/\/[^\s/$.?#].[^\s]*$`. FTP or FTPS URL. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
ftp://files.example.com✓ Matches
ftps://secure.example.com/pub/file.zip✓ Matches
ftp://user@host.com/path✓ Matches
http://example.com✗ No match
ftp://✗ No match
sftp://example.com✗ No match

Code Examples

javascript

const regex = /^ftps?:\\/\\/[^\s\/$.?#].[^\s]*$/;
const isValid = regex.test(value);

python

import re
pattern = r'^ftps?:\/\/[^\s/$.?#].[^\s]*$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^ftps?:\/\/[^\s/$.?#].[^\s]*$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^ftps?:\\/\\/[^\s\/$.?#].[^\s]*$/', $value)) {
    echo "valid";
}

java

String pattern = "^ftps?:\\/\\/[^\\s/$.?#].[^\\s]*$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.