开发者

regular expression to match files

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.开发者_C百科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


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

if you need to use regex, use find

find . -regex '.*/regularexpression'


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜