Using XPath, I would like to "Match the whole word" (option for the user, as in VS search).
It seems that the function containsand matchesoperate similarly, although coincidentally permits the use of type flags ifor case insensitivity.
In other words, I get the same results with these two XPath queries:
<pets>
<dog name="Rupert" color="grey"/>
<dog name="Ralph" color="brown"/>
<cat name="Marvin the Cat" color="white"/>
<cat name="Garfield the Cat" color="orange"/>
<cat name="Cat" color="grey"/>
<cat name="Fluffy" color="black"/>
</pets>
Matches XPath: //cat[descendant-or-self::*[@*[matches(.,'Cat')]]]
returns:
<cat name="Marvin the Cat" color="white"/>
<cat name="Garfield the Cat" color="orange"/>
<cat name="Cat" color="grey"/>
Contains XPath: //cat[descendant-or-self::*[@*[contains(.,'Cat')]]]
returns:
<cat name="Marvin the Cat" color="white"/>
<cat name="Garfield the Cat" color="orange"/>
<cat name="Cat" color="grey"/>
But I would like to use matchesto return results that match only the whole word "Cat":
<cat name="Cat" color="grey"/>
How can I customize a match query to match a whole word?
EDIT: I forgot to mention that I need to use the match function because I need a case-sensitivity flag.