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

11
SSnR.py
View File

@ -51,7 +51,7 @@ def main():
# Compile regex
try:
ex = compile_regex(args["regex"])
ex = compile_regex(args["regex"], args["ignore_case"])
except SyntaxError as exception:
print("Error when compiling regex: " + str(exception))
return -1
@ -63,7 +63,7 @@ def main():
filenames = []
if args["regex_input"] is not None:
try:
input_ex = compile_regex(args["regex_input"])
input_ex = compile_regex(args["regex_input"], False)
except SyntaxError as exception:
print("Error when compiling input regex: " + str(exception))
return -1
@ -101,7 +101,7 @@ def main():
output_files = []
if args["regex_output"] is not 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
for input_filename in filenames:
try:
@ -163,11 +163,14 @@ def main():
search(ex, string, is_file)
return 0
def compile_regex(ex):
def compile_regex(ex, ignore_case):
"""
Compile regex
:param ex: Regular expression
"""
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: