match
RegExp → String → [String | Undefined]
Parameters
- rxA regular expression.
- strThe string to match against
Returns Array The list of matches or empty array.
Added in v0.1.0
Tests a regular expression against a String. Note that this function will return an empty array when there are no matches. This differs from String.prototype.match
which returns null
when there are no matches.
See also test.
R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
R.match(/a/, 'b'); //=> []
R.match(/a/, null); //=> TypeError: null does not have a method named "match"
split
(String | RegExp) → String → [String]
Parameters
- sepThe pattern.
- strThe string to separate into an array.
Returns Array The array of strings from
str
separated bysep
.
Added in v0.1.0
Splits a string into an array of strings based on the given separator.
See also join.
const pathComponents = R.split('/');
R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']
R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']
trim
String → String
Parameters
- strThe string to trim.
Returns String Trimmed version of
str
.
Added in v0.6.0
Removes (strips) whitespace from both ends of the string.
R.trim(' xyz '); //=> 'xyz'
R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']
replace
RegExp|String → String → String → String
Parameters
- patternA regular expression or a substring to match.
- replacementThe string to replace the matches with.
- strThe String to do the search and replacement in.
Returns String The result.
Added in v0.7.0
Replace a substring or regex match in a string with a replacement.
The first two parameters correspond to the parameters of the String.prototype.replace()
function, so the second parameter can also be a function.
R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
// Use the "g" (global) flag to replace all occurrences:
R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'
toLower
String → String
Parameters
- strThe string to lower case.
Returns String The lower case version of
str
.
Added in v0.9.0
The lower case version of a string.
See also toUpper.
R.toLower('XYZ'); //=> 'xyz'
toUpper
String → String
Parameters
- strThe string to upper case.
Returns String The upper case version of
str
.
Added in v0.9.0
The upper case version of a string.
See also toLower.
R.toUpper('abc'); //=> 'ABC'