tags:

views:

50

answers:

4

hi all

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

+2  A: 

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.

SHiNKiROU
please give me example
yael
You probably want ls -1, otherwise you will get multiple files per line.
mikerobi
@yeal, he gave you an example.
mikerobi
A: 

What you could use is shell filename globbing (less powerful matching that REs) described here and elsewhere

bjg
A: 

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.)

c-urchin
+2  A: 

ls only supports simple matching with ? and * and []

if you need to use regex, use find

find . -regex '.*/regularexpression'
Imre L