java regular expression question [closed]

六眼飞鱼酱① 提交于 2019-12-14 03:37:09

问题


I want a regular expression that can match <FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT> or

<LI><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></LI> and it should not be greedy


回答1:


Three questions in as many hours. Must be a record of some sorts.

For the sake of humanity, don't use regular expressions to parse XML!




回答2:


You should not be using regular expressions for this




回答3:


Why not use a Java XML parser?




回答4:


You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts

the beginning of the answer to this exact question with over 4300 up votes. If you don't understand this and insist on ignoring this advice then you probably should not be programming.

What happens when FACE and SIZE are in opposite order?



来源:https://stackoverflow.com/questions/3495819/java-regular-expression-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!