1

Let's say i'm given a string

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

How can I use regexp-match in order to show "6.86" without knowing the size of the number, or the number used.

So, it could be "x.xx", "xx.xx", "xxx.xx", and so on.

  • Regular expressions are usually not the best ways to parse HTML. See: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – 2Cubed Aug 01 '16 at 09:38

2 Answers2

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

Ouput:

'("<span class='price'>6.86</span>" "6.86")
soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Perhaps better to use `#px"\\d+(?:\\.\\d+)?"` since `[0-9.]*` matches empty values as well as `.3.2.3.` – Sylwester Aug 01 '16 at 23:23
0

my version:

(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")
simmone
  • 379
  • 1
  • 11