classes · quantifiers · anchors

Regex generator

Describe what the field should accept, get a pattern with every piece explained, check it against sample lines and copy it in the flavour you need.

Allowed characters
Anchors

The rules and the sample lines stay in this tab. Nothing is sent anywhere, and the pattern is run by the browser's own regular-expression engine.

Short answer: for a username of 3–16 letters, digits or underscores, the pattern is ^[A-Za-z0-9_]{3,16}$. The ^ and $ make the whole field have to match, the class lists what may appear, and {3,16} is the length rule — drop any of the three and the pattern accepts something it should not.

Why anchors are the part people forget

Without ^ and $ the pattern matches a fragment, so[A-Za-z0-9_]{3,16} happily accepts not a valid username! because a run of valid characters sits inside it. Anchoring turns a search into a validation, and the page warns whenever one of the two is missing.

Worked example

A six-digit PIN is ^\d6$, and the same rule through the builder is digits only, exactly six, both anchors. The class route spells the digits as [0-9] — equivalent, and easier to read when the field also allows letters. Leading zeros survive either way, which is why a PIN is matched as text and never parsed as a number.

What this generator will not do

It will not invent a pattern for an arbitrary English sentence, because a pattern assembled from guesswork cannot be audited. If the goal is a field type the presets do not cover, build the character and length rules here, then open the regex tester to check the matches and groups it produces.

Regex generator questions

What does the generator actually build?

A character-class pattern: which characters are allowed, how many of them, and whether the whole field must match. That covers the validation rules people usually want — a username, a PIN, a slug, a reference code — and every piece of the result is explained line by line.

Why are the presets marked with their limits?

Because a pattern cannot do everything its label suggests. An email pattern checks the shape and cannot confirm the address exists; a date pattern accepts 31 February; a UUID pattern pins the version digit so v1 identifiers are rejected. Each preset states which of those applies.

How is this different from the regex tester?

The tester takes a pattern you already have and shows every match, group and replacement. The generator starts from what you want to allow and produces the pattern — then hands it to the same engine, so what you copy behaves exactly as it did on this page.

Do the patterns work outside JavaScript?

The syntax shown here — classes, quantifiers, anchors, groups — is shared with Python, PHP, Java and PCRE, so the copies for those languages work unchanged. Lookarounds and named-group syntax are where the flavours diverge, and this generator does not emit them.

Related tools

Add Scriptiii to your Home Screen

  1. Tap the Share button in Safari's toolbar.
  2. Choose Add to Home Screen.
  3. Tap Add — Scriptiii opens full screen from then on.