提取引号之间的所有内容

Mic*_*dan 1 shell grep sed regular-expression

我正在尝试使用 grep 或 sed 从看起来像的字符串中提取 url javascript:open_window("http://www.example.com/somescript.ext?withquerystring=true");

javascript 链接是由我无法控制的外部应用程序每次生成的,因此我必须提取 URL 才能使用它。我尝试过使用大量 grep 和 sed 的组合,但都失败了,但都没有奏效。

Rom*_*est 6

简单地使用 GNU grep

s='javascript:open_window("http://www.example.com/somescript.ext?withquerystring=true");'
grep -Eo 'http:[^"]+' <<<"$s"
http://www.example.com/somescript.ext?withquerystring=true
Run Code Online (Sandbox Code Playgroud)

  • 如果`grep -E` 做同样的事情,那么使用`grep -P` 对我来说没有多大意义。 (2认同)