Add case insensitive

Signed-off-by: Rémi BERTHO <remi.bertho@dalan.fr>
This commit is contained in:
Rémi BERTHO 2017-10-21 16:49:43 +02:00
parent 71426f81e1
commit d29700239b
Signed by: dalan
GPG Key ID: EE3B917931C07B64
1 changed files with 8 additions and 5 deletions

13
SSnR.py
View File

@ -51,7 +51,7 @@ def main():
# Compile regex # Compile regex
try: try:
ex = compile_regex(args["regex"]) ex = compile_regex(args["regex"], args["ignore_case"])
except SyntaxError as exception: except SyntaxError as exception:
print("Error when compiling regex: " + str(exception)) print("Error when compiling regex: " + str(exception))
return -1 return -1
@ -63,7 +63,7 @@ def main():
filenames = [] filenames = []
if args["regex_input"] is not None: if args["regex_input"] is not None:
try: try:
input_ex = compile_regex(args["regex_input"]) input_ex = compile_regex(args["regex_input"], False)
except SyntaxError as exception: except SyntaxError as exception:
print("Error when compiling input regex: " + str(exception)) print("Error when compiling input regex: " + str(exception))
return -1 return -1
@ -101,7 +101,7 @@ def main():
output_files = [] output_files = []
if args["regex_output"] is not None: if args["regex_output"] is not None:
if input_ex is None: if input_ex is None:
print("Error: Yu need a regex input file to use a regex output file") print("Error: You need a regex input file to use a regex output file")
return -1 return -1
for input_filename in filenames: for input_filename in filenames:
try: try:
@ -163,12 +163,15 @@ def main():
search(ex, string, is_file) search(ex, string, is_file)
return 0 return 0
def compile_regex(ex): def compile_regex(ex, ignore_case):
""" """
Compile regex Compile regex
:param ex: Regular expression :param ex: Regular expression
""" """
regex_compile = regex.compile(ex, regex.MULTILINE) if ignore_case:
regex_compile = regex.compile(ex, regex.MULTILINE | regex.IGNORECASE)
else:
regex_compile = regex.compile(ex, regex.MULTILINE)
if regex_compile is None: if regex_compile is None:
raise SyntaxError('Error in the regex') raise SyntaxError('Error in the regex')