DankMemer312
DankMemer312

Reputation: 37

How do I use regexp-match in Racket to only include the number with decimals

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.

Upvotes: 1

Views: 228

Answers (2)

simmone
simmone

Reputation: 379

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

Upvotes: 0

soegaard
soegaard

Reputation: 31147

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

Upvotes: 2

Related Questions