【发布时间】:2021-01-15 13:05:38
【问题描述】:
我正在尝试提取一个字符串,该字符串包含字符串的两个单词之间的所有内容:
输入:
Please find the text [ This is a sample text [ Hello World - Earth ] ]
输出:
Hello World - Earth
第二次出现“[”和“]”之间的文本
【问题讨论】:
-
这是
grep、sed等的贪婪匹配不是真正问题的地方,即echo "Please find the text [ This is a sample text [ Hello World - Earth ] ]" | sed 's/^.*[[]//;s/[]].*$//':输出`Hello World - Earth`。祝你好运。