Search code examples
regexbashls

Bash regular expression: zero to three numbers


I have this files

file00.txt
file01.txt
...
file99.txt
file102.txt
file102.txt

and

file00.extra.txt
file01.extra.txt
...

in bash (ls) with regular expression, how I can show files without .extra ?

I try with

 ls file[0-9]\{1,3\}.txt

but don't show nothing.


Solution

  • Use bash extended pattern matching:

    shopt -s extglob
    ls file+([0-9]).txt
    

    To find between 1 and 3 numbers

    ls file[0-9]?([0-9])?([0-9]).txt