正则表达式新手
我有这个示例字符串:
≪! [If Gte Mso 9]>≪Xml> ≪Br /> ≪O:Office Document Settings> ≪Br /> ≪O:Allow Png/> ≪Br /> ≪/O:Off...
我想专门针对以“≪”开头并以“>”结尾的任何内容,并将其替换为无空格“”。
一直在使用 Rubular,但我在学习如何设置这个时遇到了困难。
有什么伊达吗?
I have this sample string :
≪! [If Gte Mso 9]>≪Xml> ≪Br /> ≪O:Office Document Settings> ≪Br /> ≪O:Allow Png/> ≪Br /> ≪/O:Off...
And I would like to target specifically anything that begins in an "≪" and ends in a ">", and replace it with no-space "".
Been using Rubular, but I'm having a tricky time learning how to set this one up.
Any idaes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
应该可以解决问题。
[^>]*
表示:匹配除>
之外的任意数量的字符。should do the trick.
[^>]*
means: Match any number of characters except>
.模式很简单:
The patter is simple as that:
只是一个有用的提示,我使用 Rubular 来帮助正则表达式编写调试。
Just a helpful hint, I use Rubular to help with regex writing a debugging.
看起来您确实正在尝试使用正则表达式解析 XML,这是从该文档中提取所需数据的一种非常困难且脆弱的方法。
您最好使用 XPath 或 DOM 解析它并选择您需要的信息。
It sure looks like you're trying to parse XML with regular expressions, which is a very difficult and fragile way to extract the data you need from that document.
You might be better off parsing it and selecting the information you need using XPath or DOM.