我有一个文本(带有空格和标签的文件)
<tr>
<th width="219" rowspan="2">dsf</th>
<th width="60" rowspan="2">dsfsdf</th>
<th width="135" colspan="2">dsfdsf</th>
</tr>
和preg替换搜索
"! <tr>
<th width=\"219\" rowspan=\"2\">dsf</th>
<th width=\"60\" rowspan=\"2\">dsfsdf</th>
<th width=\"135\" colspan=\"2\">dsfdsf</th>
</tr>!is",
它不是我的正则表达式,但客户说它之前有效,经过一些研究后我发现空间或新行/ n存在问题。如果我尝试只找到一个字符串它的工作。我绑定add / r / n没什么帮助。 也许有人可以帮助我
答案 0 :(得分:1)
在查找任何空格时使用\s+
。这是便宜而简单的出路。
<tr>\s+<th width=\"219\" rowspan=\"2\">dsf</th>\s+<th width=\"60\" rowspan=\"2\">dsfsdf</th>\s+<th width=\"135\" colspan=\"2\">dsfdsf</th>\s+</tr>
有关示例,请参阅this regex101 link。