简体   繁体   中英

Regular expression match pattern php

I have an HTML string and want to extract content inside a particular tag <selection> .

Example:

Lorem Ipsum is simply <selection alt="dummy" name="dummy">dummy</selection > text the printing and typesetting <selection alt="industry" name="industry">industry</selection>. Lorem Ipsum has been the industry's <selection alt="standard" name="standard">standard</selection>dummy text ever since the 1500s.

In the above HTML string I need to extract text inside selection tags, but all tags have different attributes. Please help me with the solution.

Try this:

preg_match_all('/<selection.*?">(.*?)<\/selection.*?>/is',$sourcestring,$matches);

The $matches is your result in the form of array. I hope this is helpful to you.

You could try with this:

/<selection[^>]*>([^<]*)/g

http://regex101.com/r/pS3sM0/1

To allow tags between <selection>...</selection> :

/<selection[^>]*>(.*?)(?:<\/selection)/g

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM