[Share] Regular Expression Analysis/extraction of XML/XHTML tag attributes solution

Source: Internet
Author: User
[Share] use regular expressions to analyze/extract XML/XHTML tag attributes and view the code directly. For more information, see. PHPcode & lt ;? Php # author: selfimip # blog: http://blog.csdn.net/lgg201#mail:lgg860911@yahoo.c [share] Regular Expression Analysis/extract XML/XHTML label attributes
Let's look at the code directly. please kindly advise if you have any shortcomings ..

PHP code
  
  (?> \ W +) # tag name (? P # single attribute sub-group (?> \ S +) # front blank (? P \ w +) # attribute name = # value assignment symbol (? P
  
   
(? P
   
    
') | (? P
    
     
") # Read the quotation marks (? P # value processing sub-group (? : # Decomposition of values: 1) part of an even number of escape characters; 2) single escape character + quotation marks or non-currently used quotation marks (? P
     
      
(?> (? : \) *) # Consumes an even number of escape characters (? P
      
       
# Processing of non-escape characters \\\\(? P = quote) | (? (5) [^ '] | [^ "]) # Here, a branch is used. one side is an escape character + quotation mark, and the other side is a condition matching non-current quotation mark character )) * # Group the value for 0 or multiple times )(? P = quote) # enclosed by quotation marks) * # Duplicate attributes \ s * # trailing blank \/?> # Tag closure processing (the focus here is on the processing of attribute values, so there is no)/Xeot; # Example input $ content1 = <eot God of War Ah Republican> eot; $ content2 = <eot God of War Ah Republic "> eot; echo $ pattern. chr (10); preg_match ($ pattern, $ content1, $ matches); print_r ($ matches); preg_match ($ pattern, $ content2, $ matches ); print_r ($ matches );
      
     
    
   
  


------ Solution --------------------
No one left you. I will support it.
------ Solution --------------------
Well, the lgg201 is generally dry ....

Wait for the test to be available. do not find a bug ....
------ Solution --------------------
Yeah!

$ Content1 = <eot

Eot;

This is missing
------ Solution --------------------
Warning: preg_match () [function. preg-match]: Unknown modifier 't'in ....
------ Solution --------------------
Building separation line
------ Solution --------------------
Well, this cannot be broken through ....

Frankly speaking, I have not understood this regular expression yet. if you are free, I will study it ~~
------ Solution --------------------
To lgg201.


Can you briefly describe the situation where you need such a match?

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.