Glob - Extended unix style pathname expansion

Using Glob Patterns

Suppose you want SpaceConsistencyBear to perform an analysis on a filefirst.c, you should use the command:

  1. coala --files=src/first.c --bears=SpaceConsistencyBear --save

Note

If you don’t know the functions of a bear or how to perform the analysiswith a bear, you should go through Tutorial first.

Now, if you want all the .c files in a specific directory to be analysed,you can take help of glob patterns.

  1. coala --files='src/*.c' --bears=SpaceConsistencyBear --save

Here, *.c matches all .c files in the src directory.Going further, if you want all .c as well as .java files tobe analysed:

  1. coala --files='src/*.(java|c)' --bears=SpaceConsistencyBear --save

If you want your files argument to match all directories andsubdirectories, you can use ** glob pattern for that.

  1. files = **/*.c

Note

While using files = */.c, since we have used / in the globpattern, all .c files at least one subdirectory below the rootdirectory will be matched.

In coala, files and directories are specified by file name. To allowinput of multiple files without requiring a large number of filenames,coala supports a number of wildcards. These are based on the unix-styleglob syntax and they are not the same as regular expressions.

Note

Any glob that does not start with a / in Linux or a drive letterX: in Windows will be interpreted as a relative path. Please use commaseparated values instead of absolute path globs that start with aglob expression.

Syntax

The special characters used in shell-style wildcards are:

PATTERNMEANING
[seq]Matches any character in seq. Cannot be empty. Anyspecial character loses its special meaning in a set.
[!seq]Matches any character not in seq. Cannot be empty. Anyspecial character loses its special meaning in a set.
(seq_a|seq_b)Matches either sequence_a or sequence_b as a whole. Morethan two or just one sequence can be given.
?Matches any single character.
Matches everything but the directory separator.
*Matches everything.

Note

If you’re looking for a negation pattern to exclude paths, check out the—ignore argument or ignore .coafile option here.

Examples

[seq]

Matches any character in seq. Cannot be empty. Any special characterloses its special meaning in a set.

Opening and closing brackets can be part of a set, although closingbrackets have to be placed at the first position.

  1. >>> from coalib.parsing.Globbing import fnmatch
  2. >>> fnmatch("aaa", "a[abc]a")
  3. True
  4. >>> fnmatch("aaa", "a[bcd]a")
  5. False
  6. >>> fnmatch("aaa", "a[a]]a")
  7. False
  8. >>> fnmatch("aa]a", "a[a]]a")
  9. True
  10. >>> fnmatch("aaa", "a[]abc]a")
  11. True
  12. >>> fnmatch("aaa", "a[[a]a")
  13. True
  14. >>> fnmatch("a[a", "a[[a]a")
  15. True
  16. >>> fnmatch("a]a", "a[]]a")
  17. True
  18. >>> fnmatch("aa", "a[]a")
  19. False
  20. >>> fnmatch("a[]a", "a[]a")
  21. True

[!seq]

Matches any character not in seq. Cannot be empty. Any specialcharacter loses its special meaning in a set.
  1. >>> fnmatch("aaa", "a[!a]a")
  2. False
  3. >>> fnmatch("aaa", "a[!b]a")
  4. True
  5. >>> fnmatch("aaa", "a[b!b]a")
  6. False
  7. >>> fnmatch("a!a", "a[b!b]a")
  8. True
  9. >>> fnmatch("a!a", "a[!]a")
  10. False
  11. >>> fnmatch("a[!]a", "a[!]a")
  12. True

(seq_a|seq_b)

Matches either sequence_a or sequence_b as a whole. More than twoor just one sequence can be given.

Parentheses cannot be part of an alternative, unless they are escaped bybrackets. Parentheses that have no match are ignored as well as|-separators that are not inside matching parentheses.

  1. >>> fnmatch("aXb", "a(X|Y)b")
  2. True
  3. >>> fnmatch("aYb", "a(X|Y)b")
  4. True
  5. >>> fnmatch("aZb", "a(X|Y)b")
  6. False
  7. >>> fnmatch("aXb", "(a(X|Y)b|c)")
  8. True
  9. >>> fnmatch("a", "a|b")
  10. False
  11. >>> fnmatch("a|b", "a|b")
  12. True
  13. >>> fnmatch("(aa", "(a(a|b)")
  14. True
  15. >>> fnmatch("a(a", "(a(a|b)")
  16. False
  17. >>> fnmatch("a(a", "(a[(]a|b)")
  18. True
  19. >>> fnmatch("aa", "a()a")
  20. True
  21. >>> fnmatch("", "(abc|)")
  22. True

?

Matches any single character.
  1. >>> fnmatch("abc", "a?c")
  2. True
  3. >>> fnmatch("abbc", "a?c")
  4. False
  5. >>> fnmatch("a/c", "a?c")
  6. True
  7. >>> fnmatch("a\\c", "a?c")
  8. True
  9. >>> fnmatch("a?c", "a?c")
  10. True
  11. >>> fnmatch("ac", "a?c")
  12. False

*

Matches everything but the directory separator.

Note

The directory separator is platform specific. / is nevermatched by *. \ is matched on Linux, but not on Windows.

  1. >>> fnmatch("abbc", "a*c")
  2. True
  3. >>> fnmatch("a/c", "a*c")
  4. False
  5. >>> fnmatch("ac", "a*c")
  6. True

**

Matches everything.
  1. >>> fnmatch("abbc", "a**c")
  2. True
  3. >>> fnmatch("a/c", "a**c")
  4. True