Returns the substring before the first occurrence of the delimiter.
Input string, or null/undefined.
null
undefined
String or regex marking where to end.
Optional
Returned if s is nullish or delimiter not found (default: null).
s
The substring before the delimiter, or on_missing.
on_missing
substringBefore("path/to/file.txt", '/'); // "path"substringBefore("abc123xyz", /\d+/); // "abc"substringBefore(undefined, ':'); // nullsubstringBefore("no-needle", ':', 'default'); // 'default' Copy
substringBefore("path/to/file.txt", '/'); // "path"substringBefore("abc123xyz", /\d+/); // "abc"substringBefore(undefined, ':'); // nullsubstringBefore("no-needle", ':', 'default'); // 'default'
Returns the substring before the first occurrence of the delimiter.