Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试匹配
Begin_Page {Some Number}
在试图避免的同时
Begin_Page_{Some Number}
我试过了
$line =~ m/^Begin_Page\s/
但我注意到它有时与任何文件都不匹配,而肯定有Begin_Page 8703
Begin_Page 8703
您的正则表达式是正确的;该行应匹配:
while (<DATA>) { if (/^Begin_Page\s/) { print "OK: " } else { print "KO: " } print; }
__DATA__ test 1233 Begin_Page 123 Begin_Page_456 Begin_Page 8703
输出:
KO: test KO: 1233 OK: Begin_Page 123 KO: Begin_Page_456 OK: Begin_Page 8703