Is there a way to combine xpath and regexp to extract parts of a node value?

that's what i want ...

Assuming I'm trying to get the value "B"

<tree>
<nodea>
<nodeb>
A=foo;
B=bar;
C=goo;
</nodeb>
</nodea>
</tree>

the following magic syntax that would make sense ... I'm looking for something comparable that really works :)

string = "./nodea/nodeb/[ REGEX( 'B=(.*?);' ) ]/ $1"

Is there anything similar in any jpath xpath library?

+3
source share
1 answer

XPath 2.0 adds regular expressions . Something like this should do what you want, I think:

fn:replace(./nodea/nodeb, ".*B=(.*?);.*", "$1")
+4
source

Source: https://habr.com/ru/post/1703310/


All Articles