Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在javascript中删除表中与正则表达式匹配的所有行?_Javascript_Regex - Fatal编程技术网

有没有办法在javascript中删除表中与正则表达式匹配的所有行?

有没有办法在javascript中删除表中与正则表达式匹配的所有行?,javascript,regex,Javascript,Regex,假设我有下表: # North South 1 17 55 2 19 66 3 28 77 4 26 88 5 35 99 6 32 44 7 42 33 假设我要删除包含数字“4”的所有行,即第6行和第7行。有没有办法用javascript实现这一点 我想要的东西如下: regex = ‘%4%’; var table = document.getElementById('Table'); for (va

假设我有下表:

#   North South
1   17     55
2   19     66
3   28     77
4   26     88
5   35     99
6   32     44
7   42     33
假设我要删除包含数字“4”的所有行,即第6行和第7行。有没有办法用javascript实现这一点

我想要的东西如下:

regex = ‘%4%’;
var table = document.getElementById('Table');
for (var i=0;i < table.rows.length;i++){
 if (table.rows[i] has regex)
    table.row[i]. delete
}
regex='%4%';
var table=document.getElementById('table');
for(var i=0;i

如果您事先需要帮助,您可以尝试以下方法:

var table=document.getElementById('myTable');
对于(var i=table.rows.length-1;i>=0;i--){
if(table.rows[i].textContent.indexOf('4')!=-1){
table.rows[i].remove();
}
}

123456
789012
345678

如果连续两行中有
4
,则此操作将失败。如果删除行
1
,然后将
i
增加到
2
,则将永远不会检查位于
2
位置的行。按相反顺序访问行以避免此问题(
for(var i=table.rows.length-1;i>=0;i--)