diff --git a/salt/states/file.py b/salt/states/file.py index e45b1a14e955..b27907f8b468 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -6062,7 +6062,7 @@ def comment(name, regex, char="#", backup=".bak", ignore_missing=False): # remove (?i)-like flags, ^ and $ unanchor_regex = re.sub(r"^(\(\?[iLmsux]\))?\^?(.*?)\$?$", r"\2", regex) - uncomment_regex = "[^{}]?".format(char) + unanchor_regex + uncomment_regex = "^(?!.*{}).*".format(char) + unanchor_regex comment_regex = char + unanchor_regex # Make sure the pattern appears in the file before continuing