如何获取ID为1st属性的div标签之间的文本.仅使用正则表达式. [英] How to get text between div tags with id being 1st attribute. Only with regular expressions.
本文介绍了如何获取ID为1st属性的div标签之间的文本.仅使用正则表达式.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是场景
我正在使用此正则表达式在div标签中使用id test获取文本
I'm using this regular expression for getting the text inside div tag with id test
<div id = "test">text</div>
$regex = "#\<div id=\"test\"\>(.+?)\<\/div\>#s";
我唯一的要求是在以下情况下从div标签获取文本
My only requirement is to get the text from div tags in below scenario
<div id="test" class="teating" style="color:red" etc etc .... more attributes >
即id是div标签的第一个属性,并且可以跟随n个属性.如何仅通过正则表达式从此类标记中提取文本.请帮忙谢谢你.
i.e id being the 1st attribute of div tag and can be followed by n number of attributes. How to extract text from such a tag by regex only. Please help Thanks You.
推荐答案
使用此正则表达式:
$regex = '#<div\s+.*?id="test".*?>(.*?)</\s*div>#ims';
这篇关于如何获取ID为1st属性的div标签之间的文本.仅使用正则表达式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文