Created
September 27, 2018 12:56
-
-
Save kintoandar/a50bd6ec1e09ab7eb235858c792f4a2d to your computer and use it in GitHub Desktop.
pyregex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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