OS X在bash中用正则表达式数字找到\d不会产生预期的结果 [英] OS X Find in bash with regex digits \d not producing expected results
问题描述
我在OS X终端中使用以下正则表达式查找命令来查找具有8位数字文件名,后跟.jpg,.gif,.png或.eps扩展名的文件。即使我已经告诉OS X / BSD发现使用现代正则表达式,以下内容不会产生任何结果
find -E ./ - iregex'\d {8}'
使用 http://rubular.com/ (http://rubular.com/r/YMz3J8Qlgh)显示正则表达式模式产生预期的结果,OS X在输入时产生结果
find。 -iname'[0-9] [0-9] [0-9] [0-9] [0-9] [0-9] [0-9] [0-9]。''
但是这似乎有点长啰。
这些命令适用于OSX
find -E。 ($ p
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
此命令匹配12345678.jpg,而不是123456789.jpg
找到-E。 '$ / $ p $ / code $'$ / pre
$ / $ p $
此命令匹配12345678.jpg和123456789.jpg
$ b
。* /
等于文件夹路径或子文件夹路径
I'm using the following regex find command in OS X terminal to find a whole load of files that have 8 digit file names followed by either a .jpg, .gif, .png or .eps extension. The following produces no results even though I've told OS X/BSD find to use modern regex
find -E ./ -iregex '\d{8}'
Using http://rubular.com/ (http://rubular.com/r/YMz3J8Qlgh) shows that the regex pattern produces the expected results and OS X produces the results when typing
find . -iname '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*'
But this seems a little long winded.
解决方案 These commands works on OSX
find -E . -iregex '.*/[0-9]{8}\.(jpg|png|eps|gif)'
this command matches 12345678.jpg , not 123456789.jpg
find -E . -iregex '.*/[0-9]{8,}\.(jpg|png|eps|gif)'
this command matches 12345678.jpg and 123456789.jpg
.*/
equal the folder path or the subFolder path
这篇关于OS X在bash中用正则表达式数字找到\d不会产生预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!