Home > front end >  use regex in an array object?
use regex in an array object?

Time:02-10

how to put regex pattern as string in array of object? below code won't work, I think I'm missing some escape string

const arr = [{
  description: "(0-9)",
  pattern: "(?=.*d)",
}]

const result = arr.map(x => new RegExp(x.pattern).test(10));
console.log(result) //expect true

demo https://codesandbox.io/s/javascript-forked-ttuyp?file=/index.js

CodePudding user response:

  •  Tags:  
  • Related