README.md
1# glob-intersection
2Go package to check if the set of non-empty strings matched by the intersection of two regexp-style globs is non-empty.
3
4### Examples
5- `gintersect.NonEmpty("a.a.", ".b.b")` is `true` because both globs match the string `abab`.
6- `gintersect.NonEmpty("[a-z]+", "[0-9]*)` is `false` because there are no non-empty strings that both globs match.
7
8### Limitations
9
10- It is assumed that all input is rooted at the beginning and the end, i.e, starts and ends with the regexp symbols `^` and `$` respectively. This is done because any non-rooted expressions will always match a non-empty set of non-empty strings.
11- The only special symbols are:
12 - `.` for any character.
13 - `+` for 1 or more of the preceding expression.
14 - `*` for 0 or more of the preceding expression.
15 - `[` and `]` to define regexp-style character classes.
16 - `-` to specify Unicode ranges inside character class definitions.
17 - `\` escapes any special symbol, including itself.
18
19### Complexity
20
21Complexity is exponential in the number of flags (`+` or `*`) present in the glob with the smaller flag count.
22Benchmarks (see [`non_empty_bench_test.go`](/non_empty_bench_test.go)) reveal that inputs where one of the globs has <= 10 flags, and both globs have 100s of characters, will run in less than a nanosecond. This should be ok for most use cases.
23
24### Acknowledgements
25
26[This StackOverflow discussion](https://stackoverflow.com/questions/18695727/algorithm-to-find-out-whether-the-matches-for-two-glob-patterns-or-regular-expr) for fleshing out the logic.
27