remove (?x) modifiers

at the start of the regex there can be modifiers which also have to be removed, see #39188
This commit is contained in:
Mrten 2017-02-07 11:55:51 +01:00 committed by GitHub
parent 9d8e72b881
commit 66a25796a4

View File

@ -4107,7 +4107,9 @@ def comment(name, regex, char='#', backup='.bak'):
if not check_res: if not check_res:
return _error(ret, check_msg) return _error(ret, check_msg)
unanchor_regex = regex.lstrip('^').rstrip('$') # remove (?i)-like flags, ^ and $
unanchor_regex = re.sub(r'^(\(\?[iLmsux]\))?\^?(.*?)\$?$', r'\2', regex)
comment_regex = char + unanchor_regex comment_regex = char + unanchor_regex
# Check if the line is already commented # Check if the line is already commented