Javascript regex to match exact folder path

2k Views Asked by At

I have a folder structure like this:

main
|__Test
   |__Sub
      |__Match
      |__Match1
      |__Match2

I have a requirement to:

  1. Match only one folder - "Match"
  2. Match multiple folder - "Match, Match1, Match2

For a) I've tried:

/main\/Test\/Sub\/Match\//

But that didn't help.

Basically, I am using Isparta, and I need to exclude a few folders from instrumentation.

2

There are 2 best solutions below

0
Inquisitive On

Try this one:

\/main\/Test\/Sub\/Match([0-9])?\/?
3
Sagar V On
/^main\/Test\/Sub\/Match[0-9]?\/?$/

I used [0-9] because you mentioned a structure Like. Assume there are not only match1 and match2.