尝试在开始之前和字符串结束之后匹配。这个问题似乎在我的小巷里:How to use sed/grep to extract text between two words?
我设法匹配开始(第一场比赛)。但是对于结束(第二场比赛),它与最后一场比赛相匹配。
示例字符串:
Bob said that John is nice, which makes Bob nice.
我想得到“John is”,所以我寻找“Bob said”之间的字符串
baz="Bob said that John is nice, which makes Bob nice."
echo `echo "$baz" | sed 's/Bob said that \(.*\) nice/\1/'`
#result: John is nice, which makes Bob.
它与 last “nice”匹配,而不是 next 。有没有办法匹配下一个“好”?