regex - Hierarchical path RegExp -
I have to remove the known "level" from the hierarchical path using a regular expression; in other words, 'a / b' / X / c / d 'to' a / b / c / d 'where x could be at any level of the path.
Using Javascript as an example, I have prepared the following:
str = str.replace (/((:::(.+\/) ) | X (?: $ | \ / (. + $ "$$") /, "$ 1 $ 2") that works properly when the root of X The root is in the middle of the road, but when X comes to the end, I can create a place later to handle those examples, but will it be possible to create a better regex matching all the cases?
Thank you.
Edit : To clarify, all the levels of the path can contain any number of characters and I am only interested in deleting a level if that x matches exactly. Change: In the empty string , see the replacement below. Input a / B / x / c / d x / a / b / c / da / b / c / d / x output a / b / c / da / b / c / da / b / c / d explanation -
\ b x / - or
> < / Li> Li> - match
/ x , if lookahead (? = $) can assume that the end of the string is
Comments
Post a Comment