Regex 如何通过shell优雅地解析Markdown中的URL?
我有这样一个降价文本:Regex 如何通过shell优雅地解析Markdown中的URL?,regex,bash,shell,awk,sed,Regex,Bash,Shell,Awk,Sed,我有这样一个降价文本: this is a [sample1](http://sample1.com/) link. this is a [sample2](http://sample2.com/) link. this is a [sample3](http://sample3.com/) link. ... sample1 http://sample1.com sample2 http://sample2.com sample3 http://sample3.com 我希望输出每个链接,
this is a [sample1](http://sample1.com/) link.
this is a [sample2](http://sample2.com/) link.
this is a [sample3](http://sample3.com/) link.
...
sample1 http://sample1.com
sample2 http://sample2.com
sample3 http://sample3.com
我希望输出每个链接,如下所示:
this is a [sample1](http://sample1.com/) link.
this is a [sample2](http://sample2.com/) link.
this is a [sample3](http://sample3.com/) link.
...
sample1 http://sample1.com
sample2 http://sample2.com
sample3 http://sample3.com
但是我的代码非常混乱(使用了grep
,sed
,awk
和一些管道)
如何优雅地做到这一点
sed -rn 's@^.*\[(.*)\]\((.*)/.*$@\1 \2@p'
使用@作为sed分隔符,关注括号中的数据,并使用\1和\2打印它们
(.*\[)(.*)(\]\()(http:.+)(\/\) link)