Add case insensitive
Signed-off-by: Rémi BERTHO <remi.bertho@dalan.fr>
This commit is contained in:
parent
71426f81e1
commit
d29700239b
1 changed files with 8 additions and 5 deletions
13
SSnR.py
13
SSnR.py
|
@ -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,12 +163,15 @@ 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
|
||||
"""
|
||||
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:
|
||||
raise SyntaxError('Error in the regex')
|
||||
|
|
Loading…
Reference in a new issue