DD
DevDash

Regex for GitHub Repository URL

Regex Pattern

^https:\/\/github\.com\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/?$

GitHub repository URL

Quick Answer

The regex pattern for github repository url is `^https:\/\/github\.com\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/?$`. GitHub repository URL. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
https://github.com/facebook/react✓ Matches
https://github.com/vercel/next.js✓ Matches
https://github.com/user/repo/✓ Matches
http://github.com/user/repo✗ No match
github.com/user/repo✗ No match
https://gitlab.com/user/repo✗ No match

Code Examples

javascript

const regex = /^https:\\/\\/github\.com\\/[a-zA-Z0-9._-]+\\/[a-zA-Z0-9._-]+\\/?$/;
const isValid = regex.test(value);

python

import re
pattern = r'^https:\/\/github\.com\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/?$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^https:\/\/github\.com\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/?$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^https:\\/\\/github\.com\\/[a-zA-Z0-9._-]+\\/[a-zA-Z0-9._-]+\\/?$/', $value)) {
    echo "valid";
}

java

String pattern = "^https:\\/\\/github\\.com\\/[a-zA-Z0-9._-]+\\/[a-zA-Z0-9._-]+\\/?$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.