如何在Perl中匹配shell风格的字符串?例如:
foo*
{bar,baz}.smth
joe?
foobar[0-9]
Run Code Online (Sandbox Code Playgroud)
使用正则表达式
你的例子是:
/foo.*(bar|baz)\.smth joe/
/foobar\d/
但是,如果你真正想要的是类似shell的文件名扩展(例如上面是在上下文中ls foobar[0-9]),请使用glob()函数:
my @files = glob("foo* {bar,baz}.smth joe");
my @foobar_files = glob("foobar[0-9]");
请注意,Perl中正则表达式的语法不是文件名扩展语言的语法
| 归档时间: |
|
| 查看次数: |
134 次 |
| 最近记录: |