JS Built-ins
RegExpbeginner

RegExp Constructor β€” digit pattern

πŸ“– 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('^\\d+$') matches strings of only digits.

Challenge: Verify that new RegExp('^\\d+$').test('123') returns true.

πŸ’‘ Hints (1)
  • β€’ In a string passed to new RegExp, backslashes must be doubled: \\d