Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions

Status
Not open for further replies.

kenche

Technical User
Joined
Jun 6, 2001
Messages
3
Location
CA
hi,
I'm trying to apply a filter, and it works fine as it is. The only thing is right now the filter only works on exact matches. Is there a way for me to use wildcards or regular expressions? I've attached a code snippet below. I'd greatly appreciate any advice.

Kenneth

var filterPath;
var subTree;
filterPath = "/contacts/contact/LastName [. = 'Ch'"]";
subTree = xmldoc.selectSingleNode(filterPath);

// is there a way to match Chan, Cheung, Chang, etc.
 
regular expressions aren't built in to xpath. this is such a rediculous exclusion it makes me wonder who comes up with these specifications.
there is however some partial regex stuff which might do what you want (it's like how i'd expect a kid to design pattern matching :). the function starts-with(a,b) returns true if value a starts with b. so you could have starts-with(@name, 'Ch').
there's also a few other matching things, like substring() substring-before/after() and translate() is particularly useful.

hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top