import re


def filter_arguments(arguments, fuzz_target_name=None):
  """Filter arguments, removing testcase argument and fuzz target binary
  names."""
  # Filter out %TESTCASE*% argument.
  arguments = re.sub(r'[^\s]*%TESTCASE(|_FILE_URL|_HTTP_URL)%', '', arguments)
  if fuzz_target_name:
    arguments = arguments.replace(fuzz_target_name, '')

  return arguments.strip()