繁体   English   中英

正则表达式匹配模式php

[英]Regular expression match pattern php

我有一个HTML字符串,想要提取特定标记<selection>内的内容。

例:

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.

在上面的HTML字符串中,我需要在selection标签中提取文本,但是所有标签都具有不同的属性。 请帮我解决。

尝试这个:

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

$ matches是数组形式的结果。 希望对您有帮助。

您可以尝试以下操作:

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

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

要在<selection>...</selection>之间添加标签:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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