XPathを使用して、「単語全体に一致」したいと思います(VS検索と同じように、ユーザーのオプション)。
大文字と小文字を区別しないなどのフラグを使用できますが、関数contains
と機能は同様に機能するようです。matches
i
つまり、次の 2 つの XPath クエリで同じ結果が得られます。
<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"/>
matches
しかし、「Cat」の単語全体のみに一致する結果を返すために使用したいと思います。
<cat name="Cat" color="grey"/>
単語全体に一致するように一致クエリを調整するにはどうすればよいですか?
編集:大文字と小文字を区別しないフラグが必要なため、matches関数を引き続き使用する必要があることを忘れていました。