如何用正则表达式匹配嵌套的标签

chyich 2004-06-23 11:40:44
有这么一个字符串:

发表时间: {--发布时间 格式="yyyy-MM-dd"   
阅读数:{--点击次数 --}   
文章来源:{--来源 --}
{--相关文章 每行显示条数="1" 前缀="·" 日期格式="(yyyy-MM-dd)" 显示条数="8" 显示长度="40" 跟随方式="跟随" 显示图标="false" 日期样式类名="saw" --}
<table width="75%" border="0" height="20" align="center" cellspacing="0" cellpadding="0">
<tr>
<td height="43">
<div align="center">本栏目共有12页 首页  第1页 第2页 第3页 第4页   尾页</div>
</td>
</tr>
</table>

--}
<table width="75%" border="0" height="20" align="center" cellspacing="0" cellpadding="0">
<tr>
<td height="6">
<div align="center"></div>
</td>
</tr>
</table>


写一个正则表达式先匹配最外层的"{--发布时间 ..... --}"这一个字符串,然后再找嵌套在这个字符串里的用{-- ....... --}的括起来的字符串.
...全文
346 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
52juanjuan 2004-06-23
  • 打赏
  • 举报
回复
is good
ice_berg16 2004-06-23
  • 打赏
  • 举报
回复
re = /\{\-\-(.+)\-\-\}/g
先用这个正则取出最外层的
arr = str.match(re);
再用
re2 = /\{\-\-(.+?)\-\-\}/g
arr2 = arr[0].match(re2);
数组arr2就是你想要的内容

chyich 2004-06-23
  • 打赏
  • 举报
回复
up

87,919

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧