Regular Expressions
This page will help you add regular expressions in Linklever.
Regular expressions (regexes) can be tricky, but you don't have to understand them to use them in 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.
| Regex | Function | Explanation |
|---|---|---|
^https://example\.com$ | Exact Match | Match a URL, e.g. https://example.com |
^https://subdomain\.example\.com$ | Exact Subdomain Match | Match a URL with a subdomain, e.g. https://subdomain.example.com |
^https://example\.com\/path$ | Exact Path Match | Match a URL with a path, e.g. https://example.com/path |
^(https?:\/\/)?(www\.)?example\.com(\/path)?$ | Optional protocol, www, and path | Match https://www.example.com/path but https, http, www, and /path are optional. |
Asking an AI
AI tools like ChatGPT are effective at generating 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:
^- Asserts the start of the string.(https?:\/\/)?- Matcheshttp://orhttps://, optionally (the?makes it optional).(www\.)?- Matcheswww.optionally.example\.com- Matches the domainexample.com.$- Asserts the end of the string.
Regex quick facts
^means "match a URL starting with", e.g.^example.commatchesexample.combut notwww.example.com$means "match a URL ending with", e.g.example.co$matchesexample.cobut notexample.co.uk- Use
\.to match a dot, e.g.example\.commatchesexample.com - Use
\/to match a forward-slash, e.g.example\.com\/pathmatchesexample.com/path - Use
.to match any character e.g.example.commatchesexample.comandexampleZcom. - Use
*to match 0 or more, e.g.a*okmatchesaokandok - Use
+to match 1 or more, e.g.a+okmatchesaokbut notok - Use
?to make something optional, e.g.(https)?matcheshttps://andhttp:// - Use
()to make a group, e.g.(www\.)?example\.commatcheswww.example.comandexample.com - Use
[]to match multiple values, e.g.([\w\d]+)?\.?example\.commatchessubdomain1.example.cometcsubdomain2.example.com - Use
\wto match any letter, a to z or A to Z. - Use
\dto match any number, 0 to 9.