in reply to Re: On Interviewing and Interview Questions
in thread On Interviewing and Interview Questions

I'd grin and point out that trick questions aren't very nice, then tell you that there is no difference. A wildcard is a regular expression, it just happens to have different syntax from the regular expressions you use in perl or grep. I'd also ask you which version of grep you meant, and enquire as to whether or not it supported PCRE or not.
You'd score points for answering back because I enjoy robust debate during an interview. However, I would argue that wildcards and regular expressions are quite different: they have different meta characters (*?[] versus \^$[].|()?*+{}) and with different meanings for those meta characters. Moreover, wildcards are used by the shell to match existing filenames, while regular expressions are not so constrained.

Mentioning different grep (and shell) versions and PCRE is a plus. A bigger plus would be to write down:

ls | grep '\.c$'
and note that this should work with all greps and Unix shells.

Replies are listed 'Best First'.
Re^3: On Interviewing and Interview Questions
by demerphq (Chancellor) on Aug 27, 2005 at 09:51 UTC

    they have different meta characters (*?[] versus \^$[].|()?*+{}) and with different meanings for those meta characters. Moreover, wildcards are used by the shell to match existing filenames, while regular expressions are not so constrained.

    Ok, and this is why i consider this partially to be a trick question, Ie one that brings up much more complex issues that it appears you realize.

    To me the glob syntax is just an impoverished regular expression language. Even glob uses similar terms to describe it. Ie, a glob pattern can be directly converted to your regex language of choice. It lacks alternation and proper quantifiers, but that doesn't make it any less regular, just less useful (but of more predictable performance).

    Anyway, I doubt I would have been so bashful in an interview scenario, I probably would have had to ask you for some clarification. "What is the difference between a wild-card and a regular expression?" to me is a pretty dodgy question. "The" difference? Umm. Which wild-card syntax and which regular expression syntax. Do you mean perl style (ir)regular-expressions or what? The second part of the question I think i would have got :-)

    ---
    $world=~s/war/peace/g