I was wondering if there were any Python packages out there that detects a regular expression from a string. Conceptually this is easy enough to do but I wanted to see if there was anyone else who has solved this problem.
To the extent that I looked around on my own, I've read the re package docs and didn't find it, and I read the best hits I could find on Stack Overflow and couldn't find one either. I've googled it and the hits I find are how to use regex to parse strings. I've searched through PyPI but the only hit I could find is 'regexgen 1.0' and that didn't seem to lead anywhere...
To be clear, what I am looking for is something to the effect of:
def detect_regex(some_string):
[does stuff..]
return regular_expression
Thoughts would be greatly appreciated. If there aren't any, I can write this myself. I just didn't want to waste time re-creating what's already been done. Thanks!
Edit:
I may not have been very clear in my question; the regex 'foo' does match the string 'foo' but my goal is the following -- given the three strings with values foo123abc
, abc078963bar
, and xyz8940baz
, the return would be ^[a-z]+[0-9]+[a-z]+$
... hypothetically. So the regex would be "general" to some extent.