<human>:  What is a good Python function to regex replace with match count.
<bot>: Here is a Python function to regex replace with match count

import re

def regex_replace(s, regex, replacement, match_count=1):
  """
  Replace all matches of regex in s with replacement.
  """
  return re.sub(regex, replacement, s, count=match_count)

# Enter the string
string = "carnation"

# Enter the regex
regex = "(.*)"

# Enter the replacement
replacement = "$1"

# Enter the match count
match_count = 1

# Calling the function
print((regex_replace(string, regex, replacement, match_count)))

#Example Output
# $1

#Remember to inspect code for bugs.