Skip to content

Instantly share code, notes, and snippets.

@kintoandar
Created September 27, 2018 12:56
Show Gist options
  • Save kintoandar/a50bd6ec1e09ab7eb235858c792f4a2d to your computer and use it in GitHub Desktop.
Save kintoandar/a50bd6ec1e09ab7eb235858c792f4a2d to your computer and use it in GitHub Desktop.
pyregex
#!/usr/bin/env python
import argparse
import re
parser = argparse.ArgumentParser(description='Python regex validator.')
parser.add_argument('-r', '--regex', required=True, type=str, help='Regular expression')
parser.add_argument('-f', '--file', required=True, type=str, help='File path')
args = parser.parse_args()
r = re.compile(args.regex, re.IGNORECASE)
with open(args.file) as f:
for line in f:
if r.match(line):
print (line.rstrip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment