I want to check regex not contains word in middle. my regex code below
/con\/.+\/top/.test("con/bottom/pop/down/top")
in this regex first and last will be "con" and "top", in between .+ it should not match /pop/.
I want to check regex not contains word in middle. my regex code below
/con\/.+\/top/.test("con/bottom/pop/down/top")
in this regex first and last will be "con" and "top", in between .+ it should not match /pop/.
You could use lookahead after each slash:
const re = /con\/((?!pop\/)[^\/]+\/)+top/;
console.log(re.test("con/bottom/pop/down/top"))
console.log(re.test("con/bottom/popo/down/top"))
console.log(re.test("con/bottom/top"))
console.log(re.test("con/pop/top"))
console.log(re.test("con/popo/top"))