Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex grep和sed正则表达式-从网页中提取URL grep-i-o']\+href[]*=[\t]*“\(ht\\\;f\)tps\?:[^“]\+”';sed-e's/^.*”\([^“]\+\)*$/\1/g'_Regex_Linux_Bash_Sed_Grep - Fatal编程技术网

Regex grep和sed正则表达式-从网页中提取URL grep-i-o']\+href[]*=[\t]*“\(ht\\\;f\)tps\?:[^“]\+”';sed-e's/^.*”\([^“]\+\)*$/\1/g'

Regex grep和sed正则表达式-从网页中提取URL grep-i-o']\+href[]*=[\t]*“\(ht\\\;f\)tps\?:[^“]\+”';sed-e's/^.*”\([^“]\+\)*$/\1/g',regex,linux,bash,sed,grep,Regex,Linux,Bash,Sed,Grep,在网上搜寻我的家庭作业问题的答案后,我终于得到了上面的答案。但是我不完全理解sed和grep使用的两个正则表达式的含义。谁能告诉我一些情况吗?提前感谢。grep命令将查找包含匹配项的任何行 grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' | sed -e 's/^.*"\([^"]\+\)".*$/\1/g' ']\+href[]*=[\t]*“\(ht\\\f\)tps\?:[^”]\+” 那是 '<

在网上搜寻我的家庭作业问题的答案后,我终于得到了上面的答案。但是我不完全理解sed和grep使用的两个正则表达式的含义。谁能告诉我一些情况吗?提前感谢。

grep命令将查找包含匹配项的任何行

grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' | sed -e 's/^.*"\([^"]\+\)".*$/\1/g'
']\+href[]*=[\t]*“\(ht\\\f\)tps\?:[^”]\+”
那是

'<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"'

如果你的老师告诉你用正则表达式解析html,你真的需要在他们的椅子上放一个图钉。你的问题是关于
grep
sed
,还是关于正则表达式?将正则表达式粘贴到regex101.com中,它会给你一个很好的解释。正如@MarcB所说的-html和正则表达式不是朋友。使用真正的pa我最喜欢的是BeautifulSoup(python)但是还有很多其他的。为什么这是离题的?是的,这是关于我的家庭作业,但并不意味着我不能在这个网站上寻求帮助。我不明白为什么这些表达是这样构造的,所以我贴了一个问题。我看不出有什么问题。为什么你不写下你所理解的内容;有人被感染的可能性给你“你缺少的部分”会更好。非常感谢你的详细回答。@whoolishbeat欢迎你。从评论中你可以看出这不是一个真正的“好问题”“按照SO的标准。但是我可以从你的评论中看出你真正想要的是什么——所以它可以被挽救。一定要环顾四周,了解人们通常会问的问题,特别是当你有家庭作业问题时,表明你已经做出了努力。如果你把你的问题扩大到“我理解这些比特意味着xyz,但我正在努力理解这一部分”,而不是“这是我在谷歌上找到的东西。帮帮我。”你就不会得到反对票。是的,这就是为什么人们似乎帮我用很多砖头盖房子的原因。我吸取了教训。顺便说一句,“sed-e's/^.*”([^“]\+)“*$/\1/g'”意味着保留所有第一个匹配的URL并删除任何不匹配的内容……不是吗?@whoolishbeat:实际上-它意味着“匹配第一个不只是空字符串的双引号”“。这可能不是第一个URL。您需要一个更接近您用于
grep
的表达式才能获得更好的机会。像这样的一行:
他说“hello”
会用你的表情返回
hello
<a     the characters <a
[^>]   not followed by a close '>'
\+     the last thing one or more times (this is really not necessary I think.
       with this, it would be "not followed by exactly one '>' which would be fine
href   followed by the string 'href'
[ ]*   followed by zero or more spaces (you don't really need the [], just ' *' would be enough)
=      followed by the equals sign
[ \t]* followed by zero or more space or tab ("white space")
"      followed by open quote (but only a double quote...)
\(     open bracket (grouping)
ht     characters 'ht'
\|     or
f      character f
\)     close group (of the either-or)
tp     characters 'tp'
s\?    optionally followed by s
       Note - the last few lines combined means 'http or https or ftp or ftps'
:      character :
[^"]\+ one or more characters that are not a double quote
       this is "everything until the next quote"