Developer Tools

Regex Generator for URL Patterns and Google Filters

Builds and tests regular expressions for URL patterns and Google Analytics filters.

Google Regex Generator tool

Set your options

Pattern type

Special characters are escaped for you, so a dot means a dot.

Use cases

  • GA4 audience conditions
  • Google Search Console URL filters
  • Nginx / Apache RewriteCond patterns

Your regular expression appears here

Pick a pattern type and type the value to match. The regex updates as you type. Add a test string to check it.

About the Google Regex Generator

A single unescaped dot in a filter can match more than you meant, and a missing anchor can pull in half your site. The Kwebby Regex Generator builds the regular expression for common URL jobs so you do not have to remember the syntax. Choose a pattern type, type a path, domain or parameter, and copy the result.

It is a URL pattern builder, not a general-purpose regex writer. It will not generate email, phone or date patterns. This page lists the eight patterns it makes and the traps to check before you paste one into a filter.

Key Takeaways

  • Kwebby's Regex Generator builds eight kinds of URL pattern: exact URL, starts with, contains, domain, any subdomain, exclude path, query parameter and file extension.
  • You type a value, copy the generated regex and can paste a sample URL into Test String to see "Match!" or "No match".
  • The tool escapes special characters in every input, so a dot in a path is not treated as "any character".
  • The test runs on your browser's JavaScript regex engine. Google's reporting tools may use another flavor, so always test in the tool where you will use the pattern.
  • The Exclude path pattern uses a negative lookahead, which RE2 does not support. In RE2-based tools, use a "does not match" option with a plain pattern instead.
  • It is not a general generator. It does not write email, phone, date or IP address patterns.

What Is the Kwebby Regex Generator?

Kwebby's Regex Generator is a free online tool that builds regular expressions for URLs. You pick one of eight pattern types, type a path, domain or parameter, and the tool writes the regex with special characters escaped. A test box tells you whether a sample URL matches, and a Copy button saves the pattern to your clipboard.

No account is needed. The pattern is built and tested in your browser as you type.

Key Features and How It Works

Eight pattern types

Each button builds one kind of pattern. Here is what every one produces for its example input:

Pattern type Example input Generated regex
Exact URL match /about-us ^/about-us$
Starts with path /blog ^/blog
Contains string checkout checkout
Domain match example.com ^(www\.)?example\.com$
Any subdomain example.com .*\.example\.com$
Exclude path /admin ^(?!.*/admin).*$
Query param utm_source [?&]utm_source=
File extension pdf \.pdf$

The caret ^ anchors the start of the value and the dollar sign $ anchors the end. Anchors are what separate "exactly /blog" from "anything that mentions blog".

Special characters escaped for you

For Exact URL match, Starts with path, Contains string, Exclude path and Query param, the tool puts a backslash before characters that regex treats as special, such as a dot, a question mark or a bracket. A path like /page.php?id=1 becomes ^/page\.php\?id=1$. Domain match, Any subdomain and File extension escape special characters too. File extension also drops a leading dot, so pdf and .pdf both give \.pdf$.

A test string check

Under Test String, paste a sample URL or path. The tool shows "Match!" or "No match" straight away. Test one URL you want to catch and one you want to leave out. If the pattern cannot be read, the tool shows no result at all.

Copy

The Generated Regex box appears as soon as you type a value, and the Copy button puts the pattern on your clipboard. Switching to another pattern type clears the input so you start fresh.

Where the patterns apply

The page lists analytics filters, audience conditions, Search Console URL filters and web server rewrite conditions as uses. Each of those has its own rules for regex, so the generated pattern is a starting point that you test in the place you will use it.

Why URL Regex Matters

Filtering by pattern lets you group all blog URLs, leave out admin pages, find every URL that carries a campaign parameter or isolate downloads by file type. Plain "contains" filters are fine for simple jobs. Regex helps when you need an exact match, a start-of-path match or several conditions in one rule.

The catch is that regex is not one language. Google's Search Console API describes its includingRegex and excludingRegex filters as taking an RE2 syntax expression. RE2 marks lookahead and backreferences as not supported. The Exclude path pattern from this generator uses a negative lookahead, so it passes the on-page test, which uses JavaScript, but fails in an RE2 tool. A small mismatch like that can silently change a report, so test where the pattern will live.

How to Use the Regex Generator

  1. Choose a pattern type. Under Pattern Type, click Exact URL match, Starts with path, Contains string, Domain match, Any subdomain, Exclude path, Query param or File extension.
  2. Enter the value. Under Input Value, type a path, domain, parameter name or extension. The box shows an example for each type, such as /about-us or utm_source.
  3. Read the Generated Regex. The pattern appears below the input as soon as you type.
  4. Test it. Paste a sample URL into Test String and look for "Match!" or "No match". Try one URL that should match and one that should not.
  5. Click Copy. Paste the pattern into your filter or rule.
  6. Test in the destination. Run the filter on real data and check that the results make sense before you rely on it.

Best Practices for URL Regex

Use the narrowest pattern that works

Exact URL match and Starts with path are safer than Contains string, which matches anywhere in the value. A "contains" pattern for checkout also matches /blog/checkout-tips.

Watch the anchors

Without ^ and $ a pattern can match part of a value. Whether a tool needs a whole-value or partial match varies. The Google Analytics Data API, for example, offers separate FULL_REGEXP and PARTIAL_REGEXP match types, so read the option you choose.

Do not paste the Exclude path pattern into an RE2 tool

Common mistake: pasting ^(?!.*/admin).*$ into a field that rejects lookahead. In tools that offer a "does not match" or exclude option, enter a plain pattern such as ^/admin there instead.

Remember what Any subdomain leaves out

The Any subdomain pattern needs a dot before the domain, so it matches blog.example.com but not example.com. To cover both, combine it with the Domain match pattern using | between the two.

Treat the extension field as one extension

File extension builds \.pdf$ and escapes what you type, so pdf|doc becomes a literal \.pdf\|doc$ that matches nothing useful. For several types, write the group by hand, for example \.(pdf|docx)$, and test it.

Document your filters

Keep a short note of what each regex is for and where it is used. Future you will not remember why [?&]utm_source= is in a rule. Build the UTM URLs those parameters come from with the UTM Link Tracker.

Common Use Cases

  • Group a section of a site. Use Starts with path for /blog or /products.
  • Exclude admin or staging paths. Use a plain pattern with a "does not match" option, or Exclude path where lookahead is supported.
  • Find campaign traffic. Use Query param for utm_source or gclid.
  • Isolate downloads. Use File extension for pdf or zip.
  • Merge www and non-www. Use Domain match so both versions fall into one rule.
  • Group subdomains. Use Any subdomain for a blog, shop or help center on its own host.
  • Draft rewrite conditions. Start with a pattern here and carry it into the URL Rewriting Tool or an Apache rule.

More tools for URLs and code live in the Developer Tools hub:

Final Thoughts

Good URL regex is narrow, anchored and tested where it will be used. Kwebby's generator gets the syntax and escaping right for eight common jobs, and the Test String box catches obvious misses before you save a filter.

Pick the pattern type you need, copy the result and test it on a real URL. Then explore the Kwebby tools list for the next job in your analytics or server setup.

FAQ

Frequently asked questions

What is a regex generator?

A regex generator writes a regular expression for you from a few choices or examples, so you do not have to remember the syntax. Kwebby's tool builds eight URL patterns from a path, domain, parameter or extension, with special characters escaped. It then lets you test a sample string.

Can the Kwebby generator make email, phone or date patterns?

No. It builds URL patterns only: exact, starts with, contains, domain, any subdomain, exclude path, query parameter and file extension. For other formats you need a general regex tool or a hand-written pattern, and you should test it against valid and invalid samples.

Why does the Exclude path pattern fail in some Google tools?

It uses a negative lookahead, (?!...). The RE2 syntax, which Google's Search Console API names for its regex filters, does not support lookahead. Use a "does not match" option with a plain pattern in those tools instead.

Does it work for Search Console and analytics filters?

The patterns are built for URL filters like those. Search Console's API takes RE2 expressions, and the contains, starts-with, exact, domain, query parameter and file extension patterns are plain regex that fits that syntax. Always test a pattern in the product where you will use it, because analytics tools differ in how they match.

How do I match a URL that has a query parameter?

Choose Query param and type the parameter name, for example utm_source. The tool builds [?&]utm_source=, which matches the parameter whether it follows the question mark or an ampersand.

Is the Kwebby Regex Generator free?

Yes. The tool is free and needs no account.

Kwebby builds software too

Need a website or app built?

Get 50% off your first project. The discount applies to your first fixed quote only. Kwebby has delivered 1,200+ projects on fixed quotes from $100.

Step 1 of 3 · What do you need?

Get a fixed quote

50% off your first project. Applies to your first fixed quote only.

What do you need?

Pick an option to see its starting price and typical timeline.