【发布时间】:2014-03-12 12:41:11
【问题描述】:
我有以下文件:
Question:What color is the sky?
Explanation:The sky reflects the ocean.
Question:Why did the chicken cross the road?
Explanation:He was hungry.
我想要获得的是("What color is the sky?", "Why did the chicken cross the road") 的列表
我正在尝试使用 perl 正则表达式来解析这个文件,但没有成功。
我将文件的全部内容放在一个名为$file 的字符串中,这就是我正在尝试的
my @questions = ($file =~ /Question:(.*)\n/g);
但这总是将整个$file 字符串返回给我。
【问题讨论】:
-
为我工作,你是如何得到字符串的?能够通过将其全部放在同一行来重现您的问题