HH\Lib\Regex\replace

Meta Engineer?

This is available as Regex\replace in the www repository.

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

namespace HH\Lib\Regex;

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

If $offset is given, replacements are made only starting from $offset. The regex pattern follows the PCRE library: https://www.pcre.org/original/doc/html/pcresyntax.html.

Throws InvariantException if $offset is not within plus/minus the length of $haystack.

Guide

Parameters

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

Returns

  • string