Show HN: I wrote a book on Python regular expressions
You might like:<p><a href="https://github.com/mtrencseni/rxe" rel="nofollow">https://github.com/mtrencseni/rxe</a><p>So you can write:<p><pre><code>  username = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '%', '+', '-']))
  domain = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '-']))
  tld = rxe.at_least_at_most(2, 6, rxe.set([rxe.range('a', 'z'), rxe.range('A', 'Z')]))
  email = (rxe
    .exactly(username)
    .literal('@')
    .exactly(domain)
    .literal('.')
    .exactly(tld)
  )</code></pre>