import re


def _replace_patterns(
    content: str, plugin_name: str, old_specifier: str, new_specifier: str
) -> str:
    """
    Replace specific patterns.

    It identifies three patterns:

    1) strings of the form:
    <plugin-name><old_specifier_set>
    2) YAML strings of the form:
    plugin-name:
      version: <old_specifier_set>
    3) strings of the form
    "<plugin-name>": {"version": "<old_specifier_set>"}

    :param content: the file content
    :param plugin_name: the plugin name
    :param old_specifier: the old specifier
    :param new_specifier: the new specifier
    :return: the new content.
    """
    # check pattern (1)
    content = re.sub(
        f"{plugin_name}{old_specifier}", f"{plugin_name}{new_specifier}", content
    )
    # check pattern (2)
    content = re.sub(
        f"({plugin_name}:\n *version: ){old_specifier}",
        rf"\g<1>{new_specifier}",
        content,
    )
    # check pattern (3)
    content = re.sub(
        f'"{plugin_name}": {{"version": "{old_specifier}"}}',
        f'"{plugin_name}": {{"version": "{new_specifier}"}}',
        content,
    )
    return content