Regex Helpers

Handlebars provides a set of built-in helpers for working with regular expressions. These helpers are used to manipulate and format strings using regex patterns, making it easier to work with complex string matching in templates.

regex

{{toRegex}}

Convert the given string to a regular expression.

Params

  • str {String}
  • returns {RegExp}

Example

{{toRegex "foo"}}

{{test}}

Returns true if the given str matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.

Params

  • str {String}
  • returns {RegExp}

Example

{{test "bar" (toRegex "foo")}}

{{test "foobar" (toRegex "foo")}}

{{test "foobar" (toRegex "^foo$")}}