Patterns

This page will help you add patterns in Linklever.

In Linklever, patterns are regular expressions (regexes), but you don't have to understand them to use Linklever. Instead, you can customize the examples here, or you can ask an AI like ChatGPT to create them for you.

Examples

You can customize these examples for your needs.

PatternFunctionExplanation
^https://example\.com$Exact MatchMatch a URL, e.g. https://example.com
^https://subdomain\.example\.com$Exact Subdomain MatchMatch a URL with a subdomain, e.g. https://subdomain.example.com
^https://example\.com\/path$Exact Path MatchMatch a URL with a path, e.g. https://example.com/path
^(https?:\/\/)?(www\.)?example\.com(\/path)?$Optional protocol, www, and pathMatch https://www.example.com/path but https, http, www, and /path are optional.

Asking an AI

AI tools like ChatGPT are effective at generating URL pattern regexes.

Example Prompt:

Write a regex that matches all the common variations of a domain.

  • https://example.com
  • http://example.com
  • www.example.com
  • example.com

Response:

Here's a regex that matches the variations of the domain example.com as specified:

^(https?:\/\/)?(www\.)?example\.com$

Explanation:

  1. ^ - Asserts the start of the string.
  2. (https?:\/\/)? - Matches http:// or https://, optionally (the ? makes it optional).
  3. (www\.)? - Matches www. optionally.
  4. example\.com - Matches the domain example.com.
  5. $ - Asserts the end of the string.

Pattern quick facts

  • ^ means "match a URL starting with", e.g. ^example.com matches example.com but not www.example.com
  • $ means "match a URL ending with", e.g. example.co$ matches example.co but not example.co.uk
  • Use \. to match a dot, e.g. example\.com matches example.com
  • Use \/ to match a forward-slash, e.g. example\.com\/path matches example.com/path
  • Use . to match any character e.g. example.com matches example.com and exampleZcom.
  • Use * to match 0 or more, e.g. a*ok matches aok and ok
  • Use + to match 1 or more, e.g. a+ok matches aok but not ok
  • Use ? to make something optional, e.g. (https)? matches https:// and http://
  • Use () to make a group, e.g. (www\.)?example\.com matches www.example.com and example.com
  • Use [] to match multiple values, e.g. ([\w\d]+)?\.?example\.com matches subdomain1.example.com etc subdomain2.example.com
  • Use \w to match any letter, a to z or A to Z.
  • Use \d to match any number, 0 to 9.