I've encountered situations where only glob-style patterns are supported and full regular expression support is not there, for instance redis keys. I'd like to know the distinction between the two. Also it makes me wonder, is implementing regex matching algorithm way harder compared to glob-style pattern that some softwares doesn't support regex at all?
-
1It's usually based on the expected use, not implementation. Often the full power and flexibility of regular expressions isn't needed, and simple pattern matching is easier for the users to understand. – Barmar May 16 '14 at 18:25
-
4Also, if you're processing filenames, it's really inconvenient to have to escape `.` all the time when using regexp. – Barmar May 16 '14 at 18:26
2 Answers
Traditional glob wildcards support a very narrow set of metacharacters — *
is "anything", ?
is an arbitrary single character; Bourne shell also supports [a-z123]
for a single character out of a set of alternatives, and [!x-z789]
any one except those listed.
Regex obviously is much richer, supporting repetitions, and (in ERE) alternation and specific numbers of repetitions. Perl-style regex further extends the formalism to the point where multiple books have been written, and more will be.
Basic regex is not altogether a lot more challenging to program than glob wildcards, and these days, a competent programmer would link to an existing library in either case, anyway.
Many simpler systems don't want to burden their users with the complexity of learning regular expressions — even basic wildcards are a challenge to explain to your average sales guy^W^W person who isn't a full-time computer user.

- 175,061
- 34
- 275
- 318
-
1I vaguely recall anecdotes of big software companies who thought even developers would not want or understand regex (and then were mystified when there was a broad and clearly articulated demand; so they put it in the next version). – tripleee May 16 '14 at 18:44
Regular expressions are used in commands / functions for pattern matching in text. For example in the pattern parameter of grep, or in programming languages.
Globbing is used by shells for matching file and directory names using wildcards. The capabilities of globbing depend on the shell. Bash, for example, supports wildcards like:
More information can be found here