我有一个包含以下内容的文件:
After learning everything you've learned so far, you may think you've bingo: got a pretty good foundation in programming Perl, since you'd already be a good way through most of the concepts many other languages entail. endbingo: But if you put down this book today and did nothing else bingo: with Perl beyond what I've already taught you, you'd miss endbingo: thats ok.
我需要一个Perl正则表达式来匹配“bingo:有一个非常好的基础”和“宾果游戏:Perl超出我已经教过你的东西”这两行......
从某种意义上说,“bingo:后跟一个标签,然后是任意一组字符,直到行尾”。
答案 0 :(得分:2)
由于您尚未发布任何自己的代码,我将假设您甚至不确定如何开始构建Perl正则表达式。以下是一些可以帮助您入门的资源。
来自Perl官方文档网站:
我意识到这并没有直接回答你的问题(正如其他人已经做过的那样),但也许它会帮助你更快地收敛解决未来问题的方法。
答案 1 :(得分:0)
在多线模式下尝试:
\Wbingo:\s.*$
\W
表示任何非字母数字字符
\s
表示白色字符(空格,制表符,换行符)
.*
表示零个或多个随机字符
$
表示行尾
答案 2 :(得分:0)
如果匹配,你只想显示带有“bingo:”和标签的行,然后
perl -ne 'print if /bingo:\s+.+$/' file
如果你想匹配单词“bingo:”而不是“endbingo:”,那么
$ perl -ne 'print if /\bbingo:\s+.+$/' file
you may think you've bingo: got a pretty good foundation in
bingo: with Perl beyond what I've already taught you,
答案 3 :(得分:0)
所以它不应该匹配endbingo?试试这个:
/(?<!end)bingo:\s+.*$/
(?&lt;!是负面的背后隐藏,是排除endbingo的正确方法,不排除“bingo:”紧跟一些非空白文本的情况。
否则,如果宾果游戏背后总是有空格,只需做/ \ sbingo:\ s +(。*)$ /
答案 4 :(得分:0)
如果您正在查看标签而不是所有空白区域都使用以下内容:
/bingo:\t.*$/
如果该行必须以“bingo:”开头,则应使用:
/^bingo:\t.*$/