麻煩的正則表達式

liuzxit 2003-02-21 05:08:30
我要動態構造一個正則表達式﹐情況如下﹕
有一個不確定的TD如﹕<td><select>......</select></td>
然后構造出正則表達式為/<select>......</select>/i
但innerHTML中的"/"我怎么處理都不行﹐replace又不行

請各位解惑
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2003-02-24
  • 打赏
  • 举报
回复
<script>
a = "﹕<td><select>......</select></td>";
alert(a.replace(/(.*<td[^<]*>)(.+)(<\/td>.*)/,"$1新内容$3"));
</script>
正则表达式 /(.*<td[^<]*>)(.+)(<\/td>.*)/
其中:
(.*<td[^<]*>) 匹配标记<td>及以前的东西包括td的属性部分 $1
(<\/td>.*) 匹配标记</td> $3
(.+) 匹配<td></td>间的内容 $2
$i为被()括起部分的匹配内容,按括号顺序

td间的内容可能是不确定的
liuzxit 2003-02-24
  • 打赏
  • 举报
回复
樓上的能否寫完整一點﹐真見笑了看不明白是怎樣通過現有的TD得出這樣的正則表達式
blues-star 2003-02-24
  • 打赏
  • 举报
回复
/<select>......<\/select>/i
xuzuning 2003-02-22
  • 打赏
  • 举报
回复
/<td[^<]*>(.+)<\/td>/
liuzxit 2003-02-21
  • 打赏
  • 举报
回复
問題是我不知道<td>里是什么內﹐select我只是舉例而已
maxtiger 2003-02-21
  • 打赏
  • 举报
回复
是呀怎么能那么用呀。
JK_10000 2003-02-21
  • 打赏
  • 举报
回复
加一个反扛跳转一下不就可以吗?

<script>
var a="fdsafdsa<select>......</select>fdsafdasfdsaf";
alert(a.replace(/<select>.*<\/select>/i,"<此处内容被替换掉了>"));
</script>

87,993

社区成员

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

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