XPath를 사용하여 "전체 단어 일치"(VS 검색과 마찬가지로 사용자에게 옵션)를 사용하고 싶습니다.XPath : 전체 단어 일치 (대/소문자를 구분하지 않는 플래그가있는 matches 함수 사용)
마치 일치하면 대소 문자를 구분하지 않기 위해 i
과 같은 플래그를 허용하지만 기능이 contains
과 matches
인 것처럼 보입니다.
<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
를 사용하고 싶습니다 : : 즉
, 나는이 두 XPath 쿼리와 동일한 결과를 얻고있다
<cat name="Cat" color="grey"/>
을
전체 단어와 일치하도록 일치 검색어를 어떻게 조정할 수 있습니까?
EDIT : 대소 문자를 구분하지 않아도되므로 대/소문자를 구분하는 기능을 사용해야합니다.
흠 .. 이것은 내가 원하는 결과를 준다. 하지만^$ 앵커에 대해 설명해 주시겠습니까? 나는 전에 그들을 사용한 적이 없다. – developer
"2 개의 메타 - 캐릭터 ..."섹션을 참조하여 답변을 추가했다. –
감사합니다. 아직 테스트를해야 할 것입니다.하지만이 트릭을 수행하는 것 같습니다! – developer