为什么此正则表达式不起作用:find ./-regex'.* \(m \ | h \)$ [英] why isn't this regex working : find ./ -regex '.*\(m\|h\)$
本文介绍了为什么此正则表达式不起作用:find ./-regex'.* \(m \ | h \)$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该正则表达式为什么不起作用?
Why isn't this regex working?
find ./ -regex '.*\(m\|h\)$
我注意到以下工作正常:
I noticed that the following works fine:
find ./ -regex '.*\(m\)$'
但是当我通过添加\|h
来添加或文件名末尾的h"时,它将无法正常工作.也就是说,它应该拾取我所有的*.m
和*.h
文件,但我什么也没回来.
But when I add the "or a h at the end of the filename" by adding \|h
it doesn't work. That is, it should pick up all my *.m
and *.h
files, but I am getting nothing back.
我在Mac OS X上.
I am on Mac OS X.
推荐答案
在Mac OS X上,您不能在基本正则表达式中使用\|
,这是find
默认使用的表达式.
On Mac OS X, you can't use \|
in a basic regular expression, which is what find
uses by default.