A positive expression matches the attribute value of an html Tag.

Source: Internet
Author: User

A positive expression matches the attribute value of an html Tag.

Today, due to work requirements, we need to get the attribute values of html tags. Now we think of a regular expression. The tags are as follows:

<Circle id = "ap_test" cx = "200" cy = "2000" r = "2" stroke = "black" stroke-width = "0" fill = "red "/>
<Circle id = "ap_test" cx = "201" cy = "2001" r = "2" stroke = "black" stroke-width = "0" fill = "red "/>
<Circle id = "ap_test" cx = "202" cy = "2002" r = "2" stroke = "black" stroke-width = "0" fill = "red "/>
<Circle id = "ap_test" cx = "203" cy = "2003" r = "2" stroke = "black" stroke-width = "0" fill = "red "/>

You need to obtain the cx and cy attribute values of the <circle/> label. After thinking about it, write:

$ Circle is the content of the above circle label

Preg_match_all ('/<\ s * circle \ s + [^>] *? Cx \ s * = \ s * (\ '| \")(.*?) \ 1 [^>] *? Cy \ s * = \ s * (\ '| \")(.*?) \ 1 [^>] *? \/? \ S *>/I ', $ circle, $ arr );

Var_dump ($ arr );

$ Arr [2] is the cx value, and $ arr [4] is the cy value.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.