Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

intxeger

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intxeger

Generate unique strings from regular expressions.

  • 0.1.1
  • PyPI
  • Socket score

Maintainers
1

IntXeger

Build Status Documentation Code Coverage PyPI MIT

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

  • Faster than both xeger and exrex.
  • 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 perfect for applications such as generating unique identifiers, producing matching strings sequentially, 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 string 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 attribute 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 timestamp.

x = intxeger.build(r"(1[0-2]|0[1-9])(:[0-5]\d){2} (A|P)M")
print(x.sample(N=2))
# ['11:57:12 AM', '01:16:01 AM']

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

Benchmark

This table, generated by benchmark.py, shows the amount of time in milliseconds required to generate N examples of each regular expression using xeger and intxeger.

regexNxegerexrexintxeger
[a-zA-Z]+1007.363.171.09
[0-9]{3}-[0-9]{3}-[0-9]{4}10011.596.250.8
[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}1000208.6291.318.28
/json/([0-9]{4})/([a-z]{4})1000133.36107.0112.18

Have a regular expression that isn't represented here? Check out our Contributing Guide and submit a pull request!

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc