Reputation: 339
I would like to replace the CSS child combinator ">" for the XPath child combinator "/".
Considering different existing CSS selectors, and after scaping some white spaces I try to match the regular expression:
([\w\-\*\.\#]|[\[[^\]]+\]])>([\w\-\*\.\#]|\[ )
and replace it with:
$1/$2
This works fine for all the cases I've found but one: when one of the selectors has only one character, and is caught between two child combinators, such as: "div>a>div".
Does anybody know how to handle the one letter character correctly?
I leave here some examples: http://fiddle.re/4xkrt
Thanks!
Upvotes: 1
Views: 170
Reputation: 3437
I must repeat Alex's question. "Why don't you just replace > with /"?
However if you insist to check that the > has content on both sides then lookarounds are the way to go.
(?<=[\w\-\*\.\#]|[\[[^\]]+\]])>(?=[\w\-\*\.\#]|\[ )
This just catches the > so replace with /
.
Upvotes: 1