@@ -391,6 +391,38 @@ Class | Meaning
391391` [^class]` | matches any single character which does *not* match the class
392392` [!class]` | same as ` ^` : negates the class
393393
394+ #### Globs Are Not Regular Expressions
395+
396+ Occasionally I get bug reports that some regular-expression-style syntax
397+ doesn't work, or feature requests to add some regular-expression-inspired
398+ syntax. Globs are not regular expressions. However, if globs are not
399+ sufficiently expressive for your filtering needs, I recommend a two stage
400+ approach using ` GlobWalk` . Something like the following will get you started:
401+
402+ ` ` ` go
403+ var matches []string
404+ err := doublestar.GlobWalk (fsys, pattern, func (p string , d fs.DirEntry ) error {
405+ if (customFilter (p, d)) {
406+ matches = append (matches, p)
407+ } else if (d.isDir ()) {
408+ return doublestar.SkipDir
409+ }
410+ return nil
411+ })
412+ return matches, err
413+ ```
414+
415+ In this example, ` pattern ` should be a glob that does a first pass at fetching
416+ the files you might be interested in; ` customFilter ` is a function that does a
417+ second pass. This second pass could be anything, including regular expressions.
418+ Try to fashion a ` pattern ` that reduces the number of files you need to
419+ consider in your second pass ` customFilter ` .
420+
421+ One final note: empty alternatives can be used to build some more complicated
422+ globs. For example, ` some{thing,} ` will match both "something" and "some".
423+ Alternatives can also be nested, like ` some{thing{new,},} ` , which would match
424+ "somethingnew", "something", and "some".
425+
394426## Performance
395427
396428```
0 commit comments