Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:22:13+00:00 2026-06-03T02:22:13+00:00

Using XPath, I would like to Match whole word (option for user, just like

  • 0

Using XPath, I would like to “Match whole word” (option for user, just like in VS search).

It seems as though the functions contains and matches work similarly though matches allows for flags like i for case insensitivity.

In other words, I am getting 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 matches to return results that match “Cat” whole word only:

<cat name="Cat" color="grey"/>

How can I adjust the matches query so it matches whole word?

EDIT:
I forgot to mention that I need to still use the matches function because I need the case insensitivity flag.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:22:16+00:00Added an answer on June 3, 2026 at 2:22 am

    What about using ^ and $ characters as anchors?

    //cat[descendant-or-self::*[@*[matches(.,'^Cat$')]]]
    

    From RegEx Syntax in XQuery 1.0 and XPath 2.0:

    Two meta-characters, ^ and $ are added. By default, the meta-character
    ^ matches the start of the entire string, while $ matches the end of
    the entire string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am selecting some nodes using XPath, and would like to use wildcards. Is
I am using .NET 4.0 and I would like to use XPath 2.0 methods
I'm new to jQuery. This would be no problem for me using XPath expressions,
using xpath, how do you select the n-th option ? <select> <option></option> <option></option> </select>
How can I just obtain the string value of a Xml node using xpath
I am using Selenium webdriver in Python for a web-scraping project. I would like
I am trying to parse an xml feed using xpath. The feed contains categories
I Would like to know what are the difference between Using Xml Parser and
I would like to compare two xml files using some kind of program (
I'm using named parameters in a query to match fields in a map-like data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.