The short answer is that you can't.
The long "language theory" answer is that the
XPath language is
produced by a <a href="http://en.wikipedia.org
/wiki/
Context_free_grammar">context free
grammar</a>, not a regular
expression. Here's XPath's grammar: http://www.w3.o
rg/TR/xpath20/#nt-bnf.
No matter how hard you try, you cannot write a regular
expression that
matches all productions of a context-free grammar. In
general,
regex's are not good for parsing languages where you have to
match
parentheses or square brackets or quotes, especially when
you start
nesting like XPath does.
It may be possible to write a regex that matches a very
small subset
of XPath, but you're already seeing how difficult that can
be.
On Jul 16, 3:33 pm, Simon Vaillancourt
<simon.vaillanco... gmail.com>
wrote:
> Hi all,
>
> I've been trying to create a regular expression to
parse an XPath.
> That was quite easy till I met some thing like this :
> Aaa/Bbb/Ccc[target="http:
//www.dummy.com/url/to/make/my/point"]/Ddd
>
> I've been trying, with my limited knowledge, to get
this :
> Aaa
> Bbb
> Ccc[target="http:
//www.dummy.com/url/to/make/my/point"]
> Ddd
>
> But of course the target attribute complicate my life.
> BTW: I'm looking for something really generic.
> Therefore :
> 1 - There might not be any attribute
> 2 - The attribute might contains something without /
> 3 - The attribute might anywhere on the XPath.
>
> Any pointer that might set me on the right track is
welcome.
>
> thx
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|