问题描述
我正在查找的文件格式为 cmn-我.flac
,其中CJK字符是可变的。
使用 find
命令,我应该使用什么正则表达式来查找名称中包含单个CJK字符的所有文件?
提示:
以下正则表达式找到所有那些有和没有 CJK字符:
find ./ -regex'。* \ .. *'#ex:cmn-我.flac
然后:
find ./ -regexcmn - 。* [\x4e00-\x9fa5] * \.flac#the`-`break =>失败
find ./ -regex。* [\x4e00-\x9fa5] * \.flac#用n个CJK字符查找=>我们离得更近了!
find ./ -regex。* [\x4e00-\x9fa5] {1} \.flac#{1}`breaks =>失败。
find ./ -regex。* [\x4e00-\x9fa5]?\.flac#the`?`breaks =>失败。
如何使它成功?
在CJK匹配部分之外,在正则表达式中出现了一个错误:- 匹配的文件格式是不是
cmn-我.flac
但是是:
./ cmn-我。 flac
-
以下命令完全可以工作,匹配
./ cmn - *。flac
其中*
是任何单个字符,包括CJK :
find ./ -regex./cmn-.\.flac
以下全面介绍,匹配
./ cmn - *。flac
其中 *
是任何一个 CJK字符 / p> <<尚未找到!帮助欢迎! >>
The files I'm looking for are of the form cmn-我.flac
, where the CJK character is variable.
Using find
command, what regexp should I use to find all files with a single CJK characters in its name?
Hints:The following regexp find all files including those with and without CJK characters :
find ./ -regex '.*\..*' # ex: cmn-我.flac
Then :
find ./ -regex "cmn-.*[\x4e00-\x9fa5]*\.flac" # the `-` breaks => fails
find ./ -regex ".*[\x4e00-\x9fa5]*\.flac" # finds with n CJK characters => we get closer!
find ./ -regex ".*[\x4e00-\x9fa5]{1}\.flac" # the `{1}` breaks => fails.
find ./ -regex ".*[\x4e00-\x9fa5]?\.flac" # the `?` breaks => fails.
How to make it works ?
There was an error in the regex, outside of the CJK matching part. The file form to match is not
cmn-我.flac
but is rather :
./cmn-我.flac
The following command fully works, matching
./cmn-*.flac
where*
is any single character, including CJK :find ./ -regex "./cmn-.\.flac"
The following fully works, matching
./cmn-*.flac
where*
is any single CJK character.<< NOT yet found ! Help welcome! >>
这篇关于使用`find`命令查找带有CJK字符的文件的正则表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!