This question already has an answer here:

Shouldn't it be .*\.ext to match files ending with extension "ext", from the aspect of regular expression?

I have tried ls *.sh, which can show all the shell script file. But if I change to ls .*\.ext, it doesn't match the shell script file though.

marked as duplicate by Jeff Schaller, Community Aug 22 '18 at 19:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Does your file name start with the literal character .? Shell globbing is not the same as regex expressions. – doneal24 Aug 22 '18 at 19:11
  • Not really. Just the general case. Something like abc.sh – Jake Pan Aug 22 '18 at 19:12

There are different kinds of regular expressions.

Here it seems you are talking about shell file name expansion. In this context, a dot is just a dot, a question mark matches a single character, the meaning of the dot in most regular expression, and the asterisk itself matches zero or more characters, whereas in regular expressions it is just a modifier applied to the previous expression.

While shell file name expansion can technically be considered a kind of regular expression, they are normally not called that.

  • Shell filename wildcards don't actually use regular expressions at all; they use what're called "globs" (or "glob patterns", or...). Glob patterns are just similar enough to regular expressions to cause lots of confusion (as in this question). – Gordon Davisson Aug 22 '18 at 23:41
  • @GordonDavisson Shell file name expansion is similar enough to regular expressions because it is some kind of regular expressions, just with different rules. – RalfFriedl Aug 23 '18 at 4:43
  • Globs are not regular expressions. They are both much less powerful than real REs, and have very different syntax. "Regular expression" is a technical term in theoretical computer science (it's something that describes a regular lauguage); it's already being abused to describe things that're similar but a bit less powerful than that (e.g. "basic" REs) and similar but a bit more powerful (e.g. Perl-compatible REs), but globs aren't even close. – Gordon Davisson Aug 23 '18 at 5:46
  • By your argument, regular expressions (standard) are not regular expressions (extended) because they are less powerful and have different syntax. The concept of regular expressions is much broader than what we usually call regular expressions. I suggest we agree to disagree. – RalfFriedl Aug 23 '18 at 5:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.