RegexWars
Tier 1 · Sorcerermatch

The Prime Detector

You are given a string of 1s. Match it only when its length is a composite number — that is, not prime and not 1.

This is the most famous regular expression ever written, and it does something regex is not supposed to be able to do: arithmetic. The idea is to ask whether the run can be divided into two or more equal groups. If it can, the length is composite. If no division works, it is prime. Invert it with a negative lookahead and you have a prime detector in twelve characters.

Your pattern0 chars · par 11
//
Flags
Start typing — tests run as you go.0 of 7 visible tests passing
Test cases
  • 1111must match

    four

  • 111111must match

    six

  • 111111111must match

    nine

  • 11must not match

    two is prime

  • 111must not match

    three is prime

  • 11111must not match

    five is prime

  • 1must not match

    one is neither

+ 4 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.