Requires the Hack Standard Library to be installed.
Facebook Engineer?

This function is available as Regex\split() in Facebook's www repository.

Splits $haystack into chunks by its substrings that match with $pattern

namespace HH\Lib\Regex;

function split(
  string $haystack,
  Pattern<Match> $delimiter,
  ?int $limit = NULL,
): vec<string>;

If $limit is given, the returned vec will have at most that many elements. The last element of the vec will be whatever is left of the haystack string after the appropriate number of splits. If no substrings of $haystack match $delimiter, a vec containing only $haystack will be returned.

Throws Invariant[Violation]Exception if $limit < 2.


  • string $haystack
  • Pattern<Match> $delimiter
  • ?int $limit = NULL


  • vec<string>