Skip to main content

Generate unique strings from regular expressions.

Project description

IntXeger

Build Status Documentation Code Coverage

IntXeger (pronounced "integer") is a Python library for generating strings from regular expressions. It was inspired by the xeger library but provides additional functionality such as:

  • Array-like indexing for mapping integers to strings which match the regex.
  • Sampling-without-replacement for generating a set of unique strings which match the regex.

These features make IntXeger more suitable than xeger for applications such as generating unique identifiers, enumerating all strings which match the regex, and more!

Installation

You can install the latest stable release of IntXeger by running:

pip install intxeger

Quick Start

Let's start with a simple example where our regex specifies a two-character strnig that only contains lowercase letters.

import intxeger
x = intxeger.build("[a-z]{2}")

You can check the number of strings that can be generated with this string using the length() method and generate the ith string which matches using the get(i) method.

assert x.length() == 26**2 # there are 676 unique strings which match this regex
assert x.get(15) == 'ap' # the 15th unique string is 'ap'

Furthermore, you can generate N unique strings which match this regex using the sample(N) method. Note that N must be less than or equal to the length.

print(x.sample(N=10))
# ['xt', 'rd', 'jm', 'pj', 'jy', 'sp', 'cm', 'ag', 'cb', 'yt']

Here's a more complicated regex which specifies a 16-digit hexadecimal string, delimited between every group of 4 digits by a dash.

x = intxeger.build("[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}")
print(x.sample(N=1))
# ['F64C-F593-5E4A-E634']

To learn more about the functionality provided by IntXeger, check out our documentation!

Project details


Download files

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

Source Distribution

intxeger-0.0.1.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distribution

intxeger-0.0.1-py2.py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page