back to Overview

_.escapeRegExp()

Escapes all reserved characters for regular expressions by preceding them with a backslash.
Util module only.

Syntax

_.escapeRegExp(s)

Parameters

s
the string to escape
(return value)
the escaped string

Description

Escapes all reserved characters for regular expressions by preceding them with a backslash.

Example

Creating regular expressions for words:

function createWordRE(s) {
    return new RegExp('' + _.escapeRegExp(s) + '');
}

See also..

  • _.format() can use escapeRegExp as escape function.
  • _.template() can use escapeRegExp as escape function.

Comments

comments powered by Disqus

back to Overview

Functions