At first, I thought the following regex wouldn't match anything, since it's empty:
const emptyText = ''
const regExp = new RegExp(`${emptyText}`)
console.log(regExp) // /(?:)/
const result = 'This shouldn\'t match'.match(regExp)
console.log(result)
But then I realized it will match everything, since everything can be /(?:)/
How to modify this regex (or code), so that an empty text (''
) doesn't match everything? And it matches nothing instead?
Current output:
[
""
]
Desired output:
null