title: Regex To Detect Composite Numbers tags: python regex prime This regular expression (in Python) detects strings of 1's whose length is composite. So strings of all 1's that do not match are prime in length. ```py r = re.compile(r"^(11+)(\1+)$") ```