method
test.AsymmetricMatchers.stringMatching
regex: string | String | RegExp
): any;
Matches any received string that matches the regular expression.
A string is the source of a regular expression, as in new RegExp(regex). It is not searched for literally, and an invalid one throws a SyntaxError. To look for a literal string, use expect.stringContaining.
expect({ id: "user-42" }).toEqual({ id: expect.stringMatching(/^user-\d+$/) });
expect({ id: "user-42" }).toEqual({ id: expect.stringMatching("^user-\\d+$") });