UNPKG

989 BJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4/**
5 * Tests a regular expression against a String. Note that this function will
6 * return an empty array when there are no matches. This differs from
7 * [`String.prototype.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
8 * which returns `null` when there are no matches.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.1.0
13 * @category String
14 * @sig RegExp -> String -> [String | Undefined]
15 * @param {RegExp} rx A regular expression.
16 * @param {String} str The string to match against
17 * @return {Array} The list of matches or empty array.
18 * @see R.test
19 * @example
20 *
21 * R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
22 * R.match(/a/, 'b'); //=> []
23 * R.match(/a/, null); //=> TypeError: null does not have a method named "match"
24 */
25
26
27var match =
28/*#__PURE__*/
29_curry2(function match(rx, str) {
30 return str.match(rx) || [];
31});
32
33module.exports = match;
\No newline at end of file