Regex to avoid escaped quotes or double quotes

I am doing an xpath compiler.

Biggest problem is how to ignore single and double quoted literals …
along
with escaped quotes.

Like the following (avoiding the quoted literal):

/some/cool/xml/path[fn:count(subelement[@title
=‘fn:count("/some/cool/xml/path[fn:count(subelement[@title
=‘fn:count()’])]")’])]

I’ll post more as I work to solve it … not even posting what i have
now as
it is too weak.

-jhn