多个模式匹配失败
我有一个变量 $data ,其中包含一堆数据;我想如果变量中存在的两个模式中的任何一个条件为 true 时进行处理,所以我编写如下代码
if ( $data =~ m/"Restore actions:"|"Setting Changes:"/)
,并将 print 语句放在 else 条件中,
不幸的是它总是转到 else,即使变量中存在这两个模式。
下面是 $data 变量包含的数据
sd: Save time: Thu ...
sd: ...
sd: Restore actions:
sd: ...
sd: Setting Changes:
sd: ...
I have a variable $data which contain a bunch of data; I want to mach if either of two pattern present in the variable the condition is true so i write the code like
if ( $data =~ m/"Restore actions:"|"Setting Changes:"/)
and I put a print statement in the else condition
unfortunately its always going to the else even though these two patterns are present in the variable.
below is the data contain by the $data variable
sd: Save time: Thu ...
sd: ...
sd: Restore actions:
sd: ...
sd: Setting Changes:
sd: ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这样:
Try it like this:
您包含的引号未出现在您尝试匹配的文本中。
更精确的
就可以了。
You included quotes that don't appear in the text you are trying to match.
and the more precise
will do.