【问题标题】:How i can get only what i s inside a double quote with a regexp?我怎样才能用正则表达式只得到双引号内的内容?
【发布时间】:2012-10-12 13:53:41
【问题描述】:

如何从该字符串中获取不带双引号的 url:

<p>The document has moved <a href="http://xxx/aaa/index.html">here</a>.</p>

【问题讨论】:

  • awk 'NR==6{print;exit}' a.html | grep [\"].*[\"] 。我用 awk 来接我想要的线路

标签: regex shell


【解决方案1】:

您可以使用正则表达式模式http:[^"]+

【讨论】:

  • 我使用了 grep /http:[^"]+/ 得到了提示。这不起作用。你能解释一下吗?
  • @curious - 学习如何使用 grep:grep --h
  • thanx 我不知道 --h 是解决方案。你的评论真的很有用
【解决方案2】:

假设 html 字符串在一个名为“regexp.html”的文件中

$ ruby -n -e 'm = $_.match(/(http[^"]+)/); puts m if m' < regexp.html 
http://xxx/aaa/index.html

仅当 url 以“http”开头时才有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2013-05-10
    • 1970-01-01
    • 2016-11-09
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多