如何在Racket中使用regexp match只包含带小数的数字

如何在Racket中使用regexp match只包含带小数的数字,racket,Racket,让我们假设我得到了一个字符串 "<span class='price'>6.86</span>" “6.86” 如何使用regexp match来显示“6.86”,而不知道数字的大小或使用的数字 所以,它可以是“x.xx”、“xx.xx”、“xxx.xx”等等。\lang racket #lang racket (define elm "<span class='price'>6.86</span>") (regexp-match "<s

让我们假设我得到了一个字符串

"<span class='price'>6.86</span>"
“6.86”
如何使用regexp match来显示“6.86”,而不知道数字的大小或使用的数字

所以,它可以是“x.xx”、“xx.xx”、“xxx.xx”等等。

\lang racket
#lang racket
(define elm "<span class='price'>6.86</span>")
(regexp-match "<span class='price'>([0-9.]*)</span>" elm)
(定义elm“6.86”) (regexp匹配“([0-9.]*)”elm)
输出:

'("<span class='price'>6.86</span>" "6.86")
(“6.86”“6.86”) 我的版本:

(regexp-match #rx"<span class='price'>([0-9]*\\.*[0-9]*)</span>" 
              "<span class='price'>6.86</span>")

'("<span class='price'>6.86</span>" "6.86")
(regexp匹配#rx“([0-9]*\\.[0-9]*)”
"6.86")
'("6.86" "6.86")

正则表达式通常不是解析HTML的最佳方法。请参阅:最好使用
\px“\\d+(?:\\.\\d+)”
,因为
[0-9.]*
匹配空值以及
.3.2.3.