27 lines
640 B
Python
27 lines
640 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
|
||
|
|
# Ensure exrex is installed
|
||
|
|
try:
|
||
|
|
import exrex
|
||
|
|
except ImportError:
|
||
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "exrex"])
|
||
|
|
import exrex
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
|
||
|
|
def main():
|
||
|
|
parser = argparse.ArgumentParser(description="Generate all possibilities from a regex")
|
||
|
|
parser.add_argument("regex", type=str, help="Regex pattern (finite)")
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
try:
|
||
|
|
for match in exrex.generate(args.regex):
|
||
|
|
print(match)
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Error: {e}", file=sys.stderr)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|