gpt4 book ai didi

regex - 使用 grep 从 html 文件中获取 src 属性

转载 作者:行者123 更新时间:2023-12-05 04:10:45 26 4
gpt4 key购买 nike

如何链接 grep 以匹配双引号之间的图像?

$ cat final.html | grep -Po 'src=\".*?\"'
src="Remix-OS-Download-Option.png"
src="VMSetup1.png"
src="VMSetup2.png"
src="VMSetup3_001.png"
src="VMSetup4.png"
src="VMSetup5.png"
src="VMSetup6.png"

预期结果:

Remix-OS-Download-Option.png
VMSetup1.png
...
VMSetup6.png

最佳答案

希望这会有所帮助。由于我们在这里使用 perl 正则表达式,您可以查看演示 here

通过管道传递您的命令: grep -Po '="\K[^"]+'

正则表达式: ="\K[^"]+

1. ="\K this will match =" and \K will reset the current match.

2. [^"]+ match all except "

完整命令:

cat final.html | grep -Po 'src=\".*?\"' | grep -Po '="\K[^"]+'

您可以选择尝试这个: cat final.html | grep -Po 'src="\K[^"]+'

关于regex - 使用 grep 从 html 文件中获取 src 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44055023/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com