Skip to content

HelloChatterbox/auto_regex

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

auto_regex

regex automated

install

install from pip

pip install auto_regex

or just bundle the python file with your project, it is standalone

usage

from auto_regex import AutoRegex
rules = [
    "say {{something}} about {topic}",
    "say {{something}} please",
    "{{user}} is my name"
]

for r in AutoRegex.get_expressions(rules):
    print(r)
    """
    ^\W*say\W+(?P<something>.*?\w.*?)\W+about\W+(?P<topic>.*?\w.*?)\W*$
    ^\W*say\W+(?P<something>.*?\w.*?)\W+please\W*$
    ^\W*(?P<user>.*?\w.*?)\W+is\W+my\W+name\W*$
    """
for kw in AutoRegex.get_kwords(rules):
    print(kw)
    """
    ['something', 'topic']
    ['something']
    ['user']
    """

rx = AutoRegex()
rx.add_rules(rules)

test = ["say hello please",
        "Jarbas is my name"]
for query in test:
    matches = list(rx.extract(query))
    print(matches)
    """
    [{'something': 'hello'}]
    [{'user': 'Jarbas'}]
    """

Caveats and known bugs

  • extra spaces will be removed

  • spaces in entities will be replaced with _ say {two words} -> say {two_words}

Credits

JarbasAI

Heavily borrowed from Padaos

About

regex automated

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages