HH\Lib\Regex\replace

Requires the Hack Standard Library to be installed.

Returns $haystack with any substring matching $pattern replaced by $replacement

namespace HH\Lib\Regex;

function replace<T as Match>(
  string $haystack,
  Pattern<T> $pattern,
  string $replacement,
  int $offset = 0,
): string;

If $offset is given, replacements are made only starting from $offset.

Throws Invariant[Violation]Exception if $offset is not within plus/minus the length of $haystack.

Parameters

  • string $haystack
  • Pattern<T> $pattern
  • string $replacement
  • int $offset = 0

Returns