Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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:
These features make IntXeger
perfect for applications such as generating unique
identifiers, producing matching strings sequentially, and more!
You can install the latest stable release of IntXeger by running:
pip install intxeger
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 i
th 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!
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
.
regex | N | xeger | exrex | intxeger |
---|---|---|---|---|
[a-zA-Z]+ | 100 | 7.36 | 3.17 | 1.09 |
[0-9]{3}-[0-9]{3}-[0-9]{4} | 100 | 11.59 | 6.25 | 0.8 |
[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4} | 1000 | 208.62 | 91.3 | 18.28 |
/json/([0-9]{4})/([a-z]{4}) | 1000 | 133.36 | 107.01 | 12.18 |
Have a regular expression that isn't represented here? Check out our Contributing Guide and submit a pull request!
FAQs
Generate unique strings from regular expressions.
We found that intxeger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.