I am trying to use ER (Extended Regular Expressions) with ls
like ls .+\..+
.
I am trying to print all files which contains an extension (I know I could have used ls *.*
, but I wanted to try using ER).
When I run that code I get this error: ls: .+..+: No such file or directory
.
You don't say what shell you are using, but they generally don't support regular expressions that way, although there are common *nix CLI tools ( grep , sed , etc) that do.
$ means "Match the end of the string" (the position after the last character in the string).
GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible. In its simplest form, when no regular expression type is given, grep interpret search patterns as basic regular expressions. To interpret the pattern as an extended regular expression, use the -E ( or --extended-regexp ) option.
One of the most used wildcards is the star or asterisk wildcard “*”. This wildcard is used to represent any character, or even no characters at all! Instead of listing all the files in the directory with “ls”, when the command “ls *.
You are confusing regular expression with shell globbing. If you want to use regular expression to match file names you could do:
$ ls | egrep '.+\..+'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With