Reputation: 2913
I used the following RE:
^file(\d{1,3})(\w*)(?:\.(\d{0,3})(\w*))?
To match the following
file1.bla
or
file1.1
or
file1.1.bla
but after:
ls "^file(\d{1,3})(\w*)(?:\.(\d{0,3})(\w*))?"
I not see any match of the relevant files why? Yael
Upvotes: 0
Views: 175
Reputation: 6249
ls
only supports simple matching with ? and * and []
if you need to use regex, use find
find . -regex '.*/regularexpression'
Upvotes: 2
Reputation: 4504
ls -1 | perl -ne 'print if /^file(\d{1,3})(\w*)(?:.(\d{0,3})(\w*))?/'
(grep -P is supposed to use Perl regexp but on my system it doesn't seem to work. The only way to be sure you're using Perl regular expressions is to use Perl.)
Upvotes: 0
Reputation: 17651
Use ls -1 | grep "^file(\d{1,3})(\w*)(?:\.(\d{0,3})(\w*))?"
instead. This pipes the output of ls to grep, and grep filters the input (which is piped from ls) with the regexp.
Upvotes: 2