Search code examples
regexbashunixglob

Globbing and Regex


I came across the following question:

Does filename “globbing” provide the expressive power of standard regular 
expressions? Explain 

.

The thing is, I know what globbing is and I know about regex. But what is this expressive power? On what basis should I answer this question? I know in globbing and regex, "?" and "*" constructs are used differently and all. Should i just mention the differences in their usage? In Wikipedia, the expressive power of regular expressions are given in terms of formal languages and automata. Is the solution that complicated? Thanks in advance!


Solution

  • The question can be rephrased as :

    Can all regexp be translated into an equivalent globbing expression, and conversely, can all globbing expressions be translated into an equivalent regexp?

    If the answer (which I leave to your sagacity) is positive, then it is said that globbing and regexp have the same expressive power.

    If not, the one that is capable of 'describing more stuff' than the other one has more expressive power than the other. Basically, it suffices to show that all globbing construct have an equivalent regexp construct, while there is at least one regexep that cannot be translated into a globbing expression to show that regexp have more expressive power. (Note that globbing has several versions (extended or not) in Bash, and regexp also come in several flavours)

    Think of the human language. The set of numbers has less expressive power than the set of words. Indeed, all numbers can be written in full words, but not all words can be expressed with numbers only (to a human I mean, of course, in a computer everything is a number)