JS Built-ins
RegExpbeginner

RegExp Constructor β€” new RegExp()

πŸ“– Usage Example
const re1 = /hello/i
const re2 = new RegExp('hello', 'i')
re1.test('Hello world') // β†’ true

Use the RegExp constructor or literal syntax to create a regular expression.

RegExp Constructor

new RegExp(pattern) creates a RegExp from a string.

Challenge: Verify that new RegExp('hello').test('hello') returns true.

πŸ’‘ Hints (1)
  • β€’ new RegExp(str) is equivalent to a literal when you need dynamic patterns