1--- 2pageid: expr.match 3title: match & imatch 4layout: docs 5section: Expression Terms 6permalink: docs/expr/match.html 7--- 8 9The `match` expression performs a glob-style match against the basename of 10the file, evaluating true if the match is successful. 11 12```json 13["match", "*.txt"] 14``` 15 16You may optionally provide a third argument to change the scope of the match 17from the basename to the wholename of the file. 18 19```json 20["match", "*.txt", "basename"] 21["match", "dir/*.txt", "wholename"] 22``` 23 24### Case sensitivity 25 26`match` is case sensitive; for case insensitive matching use `imatch` instead; 27it behaves identically to `match` except that the match is performed ignoring 28case. 29 30*Since 2.9.9.* 31 32On systems where the watched root is a case insensitive filesystem (this is the 33common case for OS X and Windows), `match` is equivalent to `imatch`. 34 35*Since 4.7.* 36 37You can override the case sensitivity of all name matching operations used 38in the query by setting the `case_sensitive` field in your query. 39 40## wildmatch 41 42*Since 3.7.* 43 44The `match` expression has been enhanced as described below. The 45[capability](/watchman/docs/capabilities.html) name associated with this 46enhanced functionality is `wildmatch`. 47 48If you want to recursively match all files under a directory, use the `**` 49glob operator along with the `wholename` scope: 50 51```json 52["match", "src/**/*.java", "wholename"] 53``` 54 55By default, paths whose names start with `.` are not included. To 56change this behavior, you may optionally provide a fourth argument 57containing a dictionary of flags: 58 59```json 60["match", "*.txt", "basename", {"includedotfiles": true}] 61``` 62 63By default, backslashes in the pattern escape the next character, so 64`\*` matches a literal `*` character. To change this behavior so 65backslashes are treated literally, set the `noescape` flag to `true` 66in the flags dictionary. (Note that `\\` is a literal `\` in JSON notation): 67 68```json 69["match", "*\\*.txt", "filename", {"noescape": true}] 70``` 71 72matches `a\b.txt`. 73 74