正则表达式匹配引号之间的字符串

hax*_*ode 1 regex linux bash shell

我正在使用shell脚本读取文件,然后将输出传递给grep并尝试提取包含在两个引号之间的字符串(同时排除引号).

./readFile.sh | grep -e "[\^\"]*[\?\"]"
Run Code Online (Sandbox Code Playgroud)

这将返回我正在阅读的文件I的全部内容.

我的文件以这种方式组织:

TITLE="foo"
DATA="bar"
SERVER="foo.bar.server"
Run Code Online (Sandbox Code Playgroud)

我在http://www.regular-expressions.info/lookaround.html阅读了正则表达式教程,并试图尽可能地使用前瞻和后视,但我不明白这里有什么问题.

Ken*_*ent 7

grep 使用look-behind 检查此示例

kent$  echo 'TITLE="foo"
DATA="bar"
SERVER="foo.bar.server"'|grep -Po '(?<=")[^"]*'
foo
bar
foo.bar.server
Run Code Online (Sandbox Code Playgroud)

替代方案是 grep -Po '"\K[^"]*'