0

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.

Jake Pan
  • 101

1 Answers1

1

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.

RalfFriedl
  • 8,981
  • 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 04: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 05: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 05:51