skip to Main Content

Javascript Regex Lookahead

I am not understanding why this regex pattern is not matching as expected. I am testing this pattern on https://regexr.com. regex =/^1?((?=d{3}))[-. ]?(d{3})$/ sample = 1(123) 123 My understanding is first pattern should be number 1 or nothing then 3…

VIEW QUESTION

Javascript – why is it consoling an empty array?

const testFolder = '../assets'; const fs = require('fs'); const array=[] const pattern=/gif/ fs.readdir(testFolder, (err, files) => { files.map(file => { if(file.search(pattern)>0) array.push(file) }); // console.log(files) }); console.log(array) It should be printing an array of all the files containing .gif extension…

VIEW QUESTION
Back To Top
Search