Regex 正则表达式:在html中匹配元素后的数值

Regex 正则表达式:在html中匹配元素后的数值,regex,sed,Regex,Sed,我有以下html: <html> <head></head> <body> <span class="hello-style" id="hello123"> hello world </span> <span class="value-style"> 1000 </span> <span class="va

我有以下html:

<html>
  <head></head>
  <body>
     <span class="hello-style" id="hello123">
        hello world
     </span>
     <span class="value-style">
        1000
     </span>
     <span class="value-style">
        2000
     </span>
     <span class="value-style">
        3000
     </span>
  </body>
</html>

你好,世界
1000
2000
3000
我想匹配
之后的每个值,这些值可以是任何值,因此上面示例的输出应该是:
1000
2000年
3000

这至少应该删除所有非数值,但不会:
curl 127.0.0.1/index.html | sed's/[a-zA-Z]/“”/“/”

编辑


curl 127.0.0.1/index.html | tr-d'\n'| sed'…'
awk
救命

$ awk '/<\/span/{f=0} f; /<span class="value-style"/{f=1}' file

    1000
    2000
    3000

$awk'/您不应该使用awk/sed工具解析html/xml内容
正确的方法是使用xml/html解析器,如:

输出:

1000
2000
3000

  • //span[@class=“value style”]
    -xpath表达式,用于仅选择
    span
    标记(具有指定的属性
    class
    )值

  • grep-o'[^[:space:]*'
    -从输出中提取非空白值


好的,即使在删除所有换行符后,它看起来都像一个简单的字符串(请参见我的编辑),也应该可以将span元素后的值与类“值样式”匹配:
谢谢!
/
1000
2000
3000