In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "positive expression how to match the attribute value of html tag", the content is easy to understand, clear, hope to help you solve the doubt, the following let Xiaobian lead you to study and learn "positive expression how to match the attribute value of html tag" this article.
Regular expressions are an essential skill for text parsing. Such as Web server log analysis, web front-end development and so on. Many advanced text editors support a subset of regular expressions, and being proficient in regular expressions can often make some of your work get twice the result with half the effort. For example, counting the number of lines of code can be done with only one regularity. The matching of nested Html tags is a difficult topic in the application of regular expressions, because it involves a lot of regular syntax, and it is also difficult. Therefore, it has more research value.
Today, due to the needs of our work, we need to obtain the attribute value of the html tag. I immediately thought of the regular expression, and the tag is as follows:
You need to get the attribute values of cx and cy of the tag, and write one after thinking for a while:
$circle is the content of the circle tag above
Preg_match_all ('/] *? cx\ slots =\ s * (\'|\ ") (. *?)\\ 1 [^ >] *? cy\ swords =\ s* (\" |\ ") (. *?)\ 1 [^ >] *?\ /?\ s * > / iTunes, $circle, $arr); var_dump ($arr)
$arr [2] is the value of cx and $arr [4] is the value of cy.
Here is an introduction to regular matching closed HTML tags (nesting is supported)
Any complex regular expression is composed of simple sub-expressions. In order to write complex regular expressions, on the one hand, we need to have the ability to simplify complex regular expressions, on the other hand, we need to think about problems from the perspective of regular engine. About the principle of regular engine, it is recommended that "Mastering Regular Expression" is called "proficient in regular expressions" in Chinese. It's a good book.
OK, first identify the problem we want to solve-- find the innerHTML of the tag of a particular id from a piece of Html text.
The biggest difficulty here is that Html tags support nesting, how can you find the closed tags corresponding to the specified tags?
We can think of it this way, first match the first starting tag, suppose it is div (?) * >) | (?) |. *) *
If you only want to match the div tag, you can use the following regular expression:
] *? > ((?) * >) | (?) |. *) *
Yes, you can modify the div to any HTML tag you want to match.
If you want to match multiple HTML tags at the same time, you can use the following regular expression:
] *? > ((?) * >) | (?) |. *) *
You can continue to add more tags to match
If you want to match tags that contain ID, you can use the following regular expression:
] *\ s [iI] [dD] = (? ["']) footer (? (Quote)\ k) [^ >] *? (/ > | > ((?) * >) |. *)
This regular matches any HTML tag whose id is footer
The above is all the content of the article "how positive expressions match the attribute values of html tags". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.