URL Regex Go Validator

Search...

⌘K

URL Regex Go Validator

Search...

⌘K


URL Regex Go Validator

URL Regex Go Validator

The Qodex URL Regex Go Validator helps developers quickly test and validate whether a string is a valid web link using regular expressions in Go. This tool is ideal for building or debugging Go applications that rely on link parsing, input validation, or web scraping. Combine it with tools like the Email Regex Go Validator, Phone Number Regex Go Validator, and Go Regex Tester to create robust and secure validation logic.

https://www.admin.google.com/
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Match 1: "https://www.admin.google.com/" at index 0
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

What is URL Regex in Go?


In Go (Golang), regular expressions are powered by the built-in regexp package. A URL regex is a pattern used to match valid website links such as https://example.com/path.


Use Go regex to:


  • Validate website inputs (links, APIs)

  • Clean up scraped URLs

  • Build route matchers in backend systems

  • Parse and extract components from URLs


Meta Characters Used in URL Regex

  • ^ : Anchors the pattern to the start of the string.

  • $ : Anchors the pattern to the end of the string.

  • . : Matches any character except newline.

  • + : One or more of the previous token.

  • * : Zero or more of the previous token.

  • ? : Zero or one of the previous token.

  • [] : Matches one character from a set.

  • () : Groups tokens together.

  • | : Acts as a logical OR.

  • \\ : Escapes a metacharacter.


 How It Works


  1. Input your URL regex pattern.

  2. Paste the URL string you want to validate.

  3. Click “Validate” to check if it matches.

  4. Use “Try Another” to repeat with different examples.


Example 1 – Basic URL Validator in Go


Test your full regex logic using the Go Regex Tester.

package main

import (
    "fmt"
    "regexp"
)

func isValidURL(url string) bool {
    var pattern = `^(http|https)://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/[a-zA-Z0-9-._~:?#@!$&'()*+,;=]*)*$`
    urlRegex := regexp.MustCompile(pattern)
    return urlRegex.MatchString(url)
}

func main() {
    testURL := "https://www.example.com/search?q=test"
    fmt.Println("Valid URL:", isValidURL(testURL))
}


Example 2 – Match Shortened URLs


Also test this pattern in the JavaScript Regex Tester if you’re working on frontend validation.

var shortURL = "http://bit.ly/3abc"
var regex = regexp.MustCompile(`^https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/[a-zA-Z0-9-]*)?$`)
fmt.Println("Valid short URL:", regex.MatchString(shortURL))


Example 3 – Check for Optional Trailing Slash


Need a realistic domain or IP for testing? Use our Domain Name Generator or IPv4 Generator.

var urlWithSlash = "https://qodex.ai/"
var regex = regexp.MustCompile(`^https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/?$`)
fmt.Println("URL has optional trailing slash:", regex.MatchString(urlWithSlash))


Pro Tips for Using URL Regex in Go


  • Always anchor patterns using ^ and $ to avoid partial matches.

  • Escape . as \\. to match literal dots in domain names.

  • Use https? to allow both HTTP and HTTPS protocols.

  • Use + to allow multiple path characters.

  • Validate full URLs including query strings and paths for robust checking.


Common Use Cases


  • Form input validation (user-submitted URLs)

  • Web scraper output cleaning

  • API URL parsing

  • CMS link validation

  • Marketing campaign tracker validation


Combine with These Tools


Frequently asked questions

What does the URL regex pattern check for?×
It validates the presence of protocol (http/https), a domain name, and optional paths or query parameters.
Can it match URLs with query strings and anchors?+
Does the tool support case-insensitive matching?+
Is this tool only for Go regex?+
Can I use it to validate API endpoints?+