Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Regular expression reverser for Python

Project Description

unmatcher tries to solve the following problem:

Given a regular expression, find any string that matches the expression.

Why? Mostly just because. But one possible application is to generate test data for string processing functions.


Most typical elements of regexes are supported:

  • multipliers: *, +
  • capture groups: |, ( ) (including backreferences)
  • character classes (\d|\w|\s etc.) and character sets ([])


unmatcher module exposes a single reverse function. It takes a regular expression - either in text or compiled form - and returns a random string that matches it:

>>> import unmatcher
>>> print unmatcher.reverse(r'\d')

Additional arguments can be provided, specifying predefined values for capture groups inside the expression. Use positional arguments for numbered groups ('\1', etc.):

>>> import unmatcher
>>> print unmatcher.reverse(r'<(\w+)>.*</\1>', 'h1')

and keyword arguments for named groups:

>>> import unmatcher
>>> print unmatcher.reverse('(?P<foo>\w+)__(?P=foo)', foo='bar')

Note that a predefined value is not validated against actual subexpression for the capture group.

Release History

This version
History Node


History Node

History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(7.4 kB) Copy SHA256 Hash SHA256
Source Sep 16, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting