Jdreamer
Jdreamer

Reputation: 61

XPath match assertion: using a dot

I am using XPath Match in SoapUI assertions to validate my XML response. I am stuck with regular expression - unable to validate this tag:

<bookValue>0.00</bookValue>

My XPath matches looks like this:

matches(//bookValue, "^[0-9.]$")

But it always return me "false". Maybe there is some problem with dot symbol?

Upvotes: 0

Views: 453

Answers (2)

Andersson
Andersson

Reputation: 52675

Your regex is incorrect. Try below instead

^[0-9]+\.[0-9]{2}$

Note that using dot inside square brackets is not good for your case as [0-9.] will match either digit or dot and adding + as [0-9.]+ might match something like ...1.2.3.4. which I guess is not what you want

P.S. As @Michael Kay correctly noticed: dot inside square brackets matches only dot (.) while outside it means any character. If you want to match dot character outside square brackets you need to use back-slash as escape symbol (\.)

Upvotes: 1

Michael Kay
Michael Kay

Reputation: 163458

Your regular expression matches any string that contains a single character which must be either a digit or a dot. Your mistake is not allowing repetition: it should be "^[0-9.]+$".

(Note, "." within square brackets matches ".", it isn't a wildcard).

But note, a better way to validate the value would be X castable as xs:decimal. That, for example, disallows having several decimal points.

Upvotes: 1

Related Questions