RegEx

Methods

(inner) getRegexSource(maybeRx) → (nullable) {string}

Description:
  • Attempts to return a regex string from maybeRx.

Source:
Example
getRegexSource(/[A-z]+/) // '[A-z]+'
getRegexSource('test') // 'test'
getRegexSource(34) // null
Parameters:
Name Type Description
maybeRx *

any time

Returns:

If maybeRx is a RegExp instance, returns its .source property. If it is a string, returns it unchanged. Otherwise, returns null.

Type
string

(inner) isRegex(val) → {Boolean}

Description:
  • Checks if value is an instance of regex

Source:
Example
isRegex(new RegExp('a')) // true
isRegex(/a/) // true
isRegex('a') // false
Parameters:
Name Type Description
val *
Returns:

true if val is an instance of RegExp

Type
Boolean

(inner) joinRegex(…expressions)

Description:
  • Joins regex together in one expression
    You can technically use strings as well
    But be careful that it's not the last element of a spread call
    Or that will be interpreted as the "options" string.

Source:
Examples
// calling using spread args
const joined = joinRegex(/[A-z]+/, /[0-9]/, 'g')
joined === /([A-z]+|[0-9])/g
// calling with an array
const joined = joinRegex([ ...allMyRegEx ], 'gi')
Parameters:
Name Type Attributes Description
expressions RegExp <repeatable>

array of regex instances.

(inner) parseArgs(…args) → {Array}

Description:
  • Helper for joinRegex that parses the args

Source:
Parameters:
Name Type Attributes Description
args * <repeatable>
Returns:

[ expressions array, options string ]

Type
Array

Methods

(inner) parseArgs(…args) → {Array}

Description:
  • Helper for joinRegex that parses the args

Source:
Parameters:
Name Type Attributes Description
args * <repeatable>
Returns:

[ expressions array, options string ]

Type
Array

(inner) joinRegex(…expressions)

Description:
  • Joins regex together in one expression
    You can technically use strings as well
    But be careful that it's not the last element of a spread call
    Or that will be interpreted as the "options" string.

Source:
Examples
// calling using spread args
const joined = joinRegex(/[A-z]+/, /[0-9]/, 'g')
joined === /([A-z]+|[0-9])/g
// calling with an array
const joined = joinRegex([ ...allMyRegEx ], 'gi')
Parameters:
Name Type Attributes Description
expressions RegExp <repeatable>

array of regex instances.

(inner) isRegex(val) → {Boolean}

Description:
  • Checks if value is an instance of regex

Source:
Example
isRegex(new RegExp('a')) // true
isRegex(/a/) // true
isRegex('a') // false
Parameters:
Name Type Description
val *
Returns:

true if val is an instance of RegExp

Type
Boolean

(inner) getRegexSource(maybeRx) → (nullable) {string}

Description:
  • Attempts to return a regex string from maybeRx.

Source:
Example
getRegexSource(/[A-z]+/) // '[A-z]+'
getRegexSource('test') // 'test'
getRegexSource(34) // null
Parameters:
Name Type Description
maybeRx *

any time

Returns:

If maybeRx is a RegExp instance, returns its .source property. If it is a string, returns it unchanged. Otherwise, returns null.

Type
string

Methods

(inner) getRegexSource(maybeRx) → (nullable) {string}

Description:
  • Attempts to return a regex string from maybeRx.

Source:
Example
getRegexSource(/[A-z]+/) // '[A-z]+'
getRegexSource('test') // 'test'
getRegexSource(34) // null
Parameters:
Name Type Description
maybeRx *

any time

Returns:

If maybeRx is a RegExp instance, returns its .source property. If it is a string, returns it unchanged. Otherwise, returns null.

Type
string

(inner) isRegex(val) → {Boolean}

Description:
  • Checks if value is an instance of regex

Source:
Example
isRegex(new RegExp('a')) // true
isRegex(/a/) // true
isRegex('a') // false
Parameters:
Name Type Description
val *
Returns:

true if val is an instance of RegExp

Type
Boolean

(inner) joinRegex(…expressions)

Description:
  • Joins regex together in one expression
    You can technically use strings as well
    But be careful that it's not the last element of a spread call
    Or that will be interpreted as the "options" string.

Source:
Examples
// calling using spread args
const joined = joinRegex(/[A-z]+/, /[0-9]/, 'g')
joined === /([A-z]+|[0-9])/g
// calling with an array
const joined = joinRegex([ ...allMyRegEx ], 'gi')
Parameters:
Name Type Attributes Description
expressions RegExp <repeatable>

array of regex instances.

(inner) parseArgs(…args) → {Array}

Description:
  • Helper for joinRegex that parses the args

Source:
Parameters:
Name Type Attributes Description
args * <repeatable>
Returns:

[ expressions array, options string ]

Type
Array