需要将所有正斜杠 (/
) 替换为 >
,但方括号中的除外。
输入字符串:
string str = "//div[1]/li/a[@href='https://www.facebook.com/']";
尝试的模式(无效):
string regex = @"\/(?=$|[^]]+\||\[[^]]+\]\/)";
var pattern = Regex.Replace(str, regex, ">");
预期结果:
">>div[1]>li>a[@href='https://www.facebook.com/']"
">>div[1]>a[1]>span[@class='_55pe'][1]"
,那么它通过了我的测试。 - Aage