JAVASCRIPT IN PRACTICE

Shortest regex (golf)

Shortest regex (golf) - hit every "match" and no "skip" using as few characters as possible. Trains regex and minimalism.

  • Short patterns
  • Alternation
  • Checking matches
Preview the first challenge →

Solving requires a free account.

Selected challenges to get started

Pick a challenge and explore the rules through a concrete example.

Warm-up

Anything (golf)

Match every non-empty string, including a lone newline. Reject only the empty string.

Preview challenge → Free account required to solve
Easy

Digits only (golf)

Match an entire non-empty string of ASCII digits 0–9. Inputs contain no newlines. Fit the pattern within the limit.

Preview challenge → Free account required to solve
Easy

Ends with -ing (golf)

Match words ending in "ing". Inputs are single lowercase ASCII words.

Preview challenge → Free account required to solve

Ready for more?

Available challenges: 5.

See all challenges →

The full catalogue requires a free account.

How should you approach these challenges?

Regex golf combines understanding regular expressions with a pattern-length constraint. It teaches you to spot shared data features and check the effects of generalisation. A short pattern fitted to the examples may not be suitable for validating arbitrary application data.

Build a correct regex separating the two example sets, then look for shared fragments, character classes and shorter alternatives. Each reduction can introduce unwanted matches. Check both pattern length and every string that should or should not match.

Explore an example: Anything (golf) →

Read the description without logging in. Solving requires a free account.