2016-08-01 67 views
1
數量

比方說,我正在給一個字符串如何使用正則表達式匹配的球拍,只包括與小數

"<span class='price'>6.86</span>" 

如何使用正則表達式匹配,以顯示「6.86」不知道號碼的大小或使用的號碼。

因此,它可以是「x.xx」,「xx.xx」,「xxx.xx」等。

+0

正則表達式是通常不解析HTML的最佳方式。請參閱:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – 2Cubed

+0

謝謝你的鏈接 – DankMemer312

回答

2
#lang racket 
(define elm "<span class='price'>6.86</span>") 
(regexp-match "<span class='price'>([0-9.]*)</span>" elm) 

輸出繼電器:

'("<span class='price'>6.86</span>" "6.86") 
+0

也許更好使用'#px「\\ d +( ?:\\。\\ d +)?「',因爲'[0-9。] *'與空值以及.3.2.3.'匹配 – Sylwester

0

我的版本:

(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")