Path match question asked in interview (tier1/2 company)

Need to implement git ignore functionality

*: match with 1 segment

**: match with 0 or more segments

*.txt: does not need to be supported.

bool IsMatch(string filePath, string pattern)

1.filePath: "/ab/cd/ef/gh/ij/lm.txt"

pattern: "/ab/*/ef/**/lm.txt"

-->return true
Reason-->{
ab cd ef gh ij lm.txt

ab * ef ** lm.txt
}

2.filePath: "/ab/cd/ef/gh/ij/lm.txt"

pattern: "/ab/*/ef/**/pq/lm.txt"
-->false

3.filePath: "/ab/cd/ef/gh/ij/lm.txt/ddd/dc/lm.txt/ddd/dd"

pattern: "/ab/*/ef/**/lm.txt/ddd/dd"

--> true


 

boolean isMatch(String filePath, String pattern){


}
Comments (1)