【发布时间】:2017-03-07 05:11:19
【问题描述】:
我是 perl 的新手,我通过 Check whether a string contains a substring 了解如何检查字符串中是否存在子字符串,现在我的情况略有不同
我有一个类似
的字符串/home/me/Desktop/MyWork/systemfile/directory/systemfile64.elf,
最后这可能是systemfile32.elf 或systemfile16.elf,所以在我的perl 脚本中,我需要检查该字符串是否包含格式为systemfile*.elf 的子字符串。
如何在 perl 中实现这一点?
我打算这样做
if(index($mainstring, _serach_for_pattern_systemfile*.elf_ ) ~= -1) {
say" Found the string";
}
【问题讨论】:
-
$string =~ /systemfile.*\.elf/你应该看看perldoc.perl.org/perlre.html -
是的,解决了,谢谢
-
你能把它作为答案发布,以便我可以输入正确答案
-
你去,张贴
-
如果存在一个名为 64bitsystemfile.elfde 的文件怎么办?你仍然会得到 systemfile 和 .elf 的匹配项
标签: string perl search perl-module