human
regex replace with match count.
assistant
Here is a Python function to regex replace with match count

import re

def regex_replace_with_match_count(s, regex, replacement, match_count=1):
    """
    Replace regex in string with replacement.
    If match_count is 1, then replace only first match.
    If match_count is 2, then replace first and second match.
    """
    if match_count == 1:
        return re.sub(regex, replacement, s)
    else:
        return re.sub(regex, replacement * match_count, s)

# Enter the string
s = "Hello, world!"

# Enter the regex
regex = "world"

# Enter the replacement
replacement = "Hello"

# Enter the match count
match_count = 2

# Calling the function
print((regex_replace_with_match_count(s, regex, replacement, match_count)))

#Example Output
# Hello, HelloHello!

#Remember to inspect code for bugs.