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

ooregex

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ooregex

A simple, object-oriented, regular expression generator.

  • 0.2.0
  • PyPI
  • Socket score

Maintainers
1

ooregex

GitHub release (latest SemVer) PyPI - Downloads GitHub Code Style - Black

A simple, object oriented, regular expression generator.

ooregex is a package aimed at providing a simple syntax for composing regular expressions, without having to memorise their syntax.

It does not guarantee that the expressions generated are the most efficient.

It is assumed that users have some understanding of regular expressions, as there's nothing preventing invalid expressions from being generated.

This project most likely still needs more testing, so I won't bump it to version 1.0 until I'm sure it's good enough.

Installation

You can install this package using pip with the command

pip install ooregex

Usage

The main purpose of this package is generating regular expressions to be used in other projects, for example, with the built-in re module.

See the full documentation here.

Import the module with:

import ooregex

Alternatively, import only the symbols that you need:

from ooregex import (...)

Now let's build an expression for matching a price tag:

import re

from ooregex import *

pattern = Regex(
    Group(name="price", expression=Regex(
        DIGIT[1:],
        Optional(DOT + DIGIT[:]))
        ),
    Group(name="currency", expression=
        AnyOf("$£€")
        ),
)
# (?P<price>\d+(?:\.\d*)?)(?P<currency>[$£€])

test_str = "Sales! Everything for 9.99£!"

price_tag = re.search(str(pattern), test_str)

if price_tag is not None:
    price = price_tag.group("price")
    currency = price_tag.group("currency")

    print(price, currency)
    # 9.99 £

Let's examine the pattern:

We have 2 groups:

  • a group named "price" consisting of:
    • one or more digits
    • optionally:
      • a dot
      • zero or more digits
  • a group named "currency" consisting of:
    • any character from "$£€"

Look how much clearer it is compared to the generated string: (?P<price>\d+(?:\.\d*)?)(?P<currency>[$£€])

Report a bug

If you find a bug, you can open an issue or email me.

License

This package is available under the MIT license.

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