gpt4 book ai didi

regex - 如何使用正则表达式在 XML 文件中查找斜杠?

转载 作者:行者123 更新时间:2023-12-04 05:51:50 26 4
gpt4 key购买 nike

我必须解析一个类似 xml 的文件并替换 /_ .

但现在我的问题是我找不到字符串 /没有找到 </ .

谁能帮我?

示例字符串:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
<tables>
<table>
<name>users</name>
<value>test/djha</value>
</table>
</tables>
</database>

最佳答案

试试这个正则表达式:(?<!<)/
它使用零宽度 "negative lookbehind" .如果前瞻内的模式无法匹配到该位置结束,则在该位置匹配。

在 XML 中,您还应该注意空标签,例如 <table name="products" /> .所以你用这样的东西更安全:

(?<!<)/(?!>)

关于regex - 如何使用正则表达式在 XML 文件中查找斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9973429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com