Zellio.io

Regex Golf

Each hole gives two lists. Your pattern has to find a match somewhere in every string on the left and nowhere in any string on the right. Any pattern that does that solves the hole; the shortest one wins it. Par is the length of the reference solution, and beating par is possible on most holes.

Practises the Regex Tester & Builder. Answers are checked here; nothing is sent anywhere.

Hole 1 · par 10

Vowels only

Match strings made entirely of lower-case vowels, and nothing that contains any other character.

Must match

  • aei
  • ou
  • eau
  • ai
  • oi

Must not match

  • cat
  • ax
  • bee
  • x
  • ae1
//0 chars

How a hole is checked

The pattern is compiled with JavaScript's RegExp and tested against each string with search semantics, so a match anywhere counts. That is why most holes need anchors: without them a pattern that matches the three-letter strings also matches the ten-letter ones. Flags are not available; if a hole needs case-insensitivity, write the ranges out.

Before it runs, the pattern is screened for shapes that backtrack catastrophically, such as nested unbounded quantifiers. A pattern flagged as likely to hang is not run, and the hole says so rather than freezing the tab.

Scoring

Score is pattern length in characters. Par is the reference solution's length, which is short but not always the shortest possible; the holes where it can be beaten are the interesting ones. Your best score per hole is kept on this device, along with a streak of consecutive days with at least one solve. Nothing is sent anywhere, and there is no leaderboard, which is deliberate: a leaderboard needs an identity and the site does not keep any.

  • Under par: shorter than the reference.
  • Par: the same length.
  • Over par: solved, but longer. Still solved.

Techniques that shorten patterns

  • Anchor only the side you need: a suffix test wants $, not both ends.
  • A backreference such as (.)\1 is shorter than listing every doubled letter.
  • Negated classes ([^,]) beat enumerating what is allowed.
  • Look at the reject list first; it decides which anchors and boundaries are unavoidable.
  • The tester tool explains any pattern token by token, which is the fastest way to see why a hole is not passing.

Questions

Does the pattern have to match the whole string?
No; it has to match somewhere in it. Add anchors when the reject list would otherwise slip through.
Is the reference the shortest answer?
Not always. It is a clean, readable solution and its length is par. Several holes have shorter answers, and finding them is the game.

Other labs