本文介绍了正则表达式在此模式中查找文字然后任意文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好我正在尝试在正则表达式中识别这样的模式: 并替换为相同的 - 最后4个属性。 < polypolygon name =PolyPolygon35height =13width =23left =346top =126visible =true壁纸=falseisreferenceobject =falsebackstyle =solidbackcolor =#3F3F3Fforecolor =blacklinestyle =solidlinewidth =1patternstyle =nonepatterncolor =blackendcolor =white gradientstop =50gradientdirection =gradientDirectionHorizo​​ntalgradientshadingstyle =gradientHorizo​​ntalFromRight> 引号中的所有数值都不重要只有< polypolygon as a literal与结尾有关的事项> 我真的需要这个模式与其属性完全匹配(不是引号中的属性值 - 它们不重要),所以我可以用任何东西替换所有最后4个属性。 如果任何人能让我开始正确的方向我可以解决它 - 我试过< polypolygon 带有数字计数 - 但这往往会导致问题无法正确识别,所以我的reg-ex可能是好的。 谢谢大家的时间和帮助。解决方案 PIEBALDConsult是对的:正则表达式是一种非常非常糟糕的方式解析HTML / XML - 它确实是一个问题,错误和挫折的秘诀 - 特别是当你需要在三个月的时间内进行微小的改变时,你已经忘记了那个不可读的正则表达式是如何工作的...... 查看 HTML Agility Pack [ ^ ] - 它可能会完成你想要的更多简单和快速的事情。 Hello I am trying to identify a pattern like this in regular expression:And replace with same - last 4 attributes. <polypolygon name="PolyPolygon35" height="13" width="23" left="346" top="126" visible="true" wallpaper="false" isreferenceobject="false" backstyle="solid" backcolor="#3F3F3F" forecolor="black" linestyle="solid" linewidth="1" patternstyle="none" patterncolor="black" endcolor="white" gradientstop="50" gradientdirection="gradientDirectionHorizontal" gradientshadingstyle="gradientHorizontalFromRight">All values in quotes are not important only this <polypolygon as a literal matters along with the ending >I really need an exact match on this pattern with its attributes (not the attribute values in quotes - they are unimportant) , so I can replace all the last 4 attributes with nothing.If any one can get me started in the right direction I can work it out - I tried <polypolygonwith a numeric count - but that tends to get problems not identifying correctly so my reg-ex is probably bad.Thank you all for your time and help. 解决方案 PIEBALDConsult is right: a regex is a very, very poor way to parse HTML / XML - it really is a recipe for problems, bugs, and frustration - particularly when you need a minor change in three months time, and you have forgotten how that unreadable Regex works...Have a look at the HTML Agility Pack[^] - it'll probably do most of what you want a lot simpler and quicker. 这篇关于正则表达式在此模式中查找文字然后任意文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 22:14