PHP:preg_replace() - 需要替换textNode字符串
我遇到以下问题,并且我不太擅长正则表达式,所以请问有人可以帮助我吗?
<div class="bulletPoints">
<div>
<a href="#autoGeneratedId0" title="test_f01"><img src="../images/test_f01.jpg" alt="test_f01"/>1</a>
<a href="#autoGeneratedId1" title="test_f02"><img src="../images/test_f02.jpg" alt="test_f02"/>2</a>
<a href="#autoGeneratedId2" title="test_f03"><img src="../images/test_f03.jpg" alt="test_f03"/>3</a>
<a href="#autoGeneratedId3" title="test_f04"><img src="../images/test_f04.jpg" alt="test_f04"/>4</a>
<a href="#autoGeneratedId4" title="test_f05"><img src="../images/test_f05.jpg" alt="test_f05"/>5</a>
<a href="#autoGeneratedId5" title="test_f06"><img src="../images/test_f06.jpg" alt="test_f06"/>6</a>
<a href="#autoGeneratedId6" title="test_f07"><img src="../images/test_f07.jpg" alt="test_f07"/>7</a>
<a href="#autoGeneratedId7" title="test_f08"><img src="../images/test_f08.jpg" alt="test_f08"/>8</a>
<a href="#autoGeneratedId8" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>9</a>
<a href="#autoGeneratedId9" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>10</a>
<a href="#autoGeneratedId10" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>11</a>
<!-- and so on -->
</div>
</div>
我需要替换每个锚标记内的图像标记后面的纯文本字符串。该字符串始终是 0 - 99 之间的数字。锚标记的 ID 和标题属性也是自动生成的。我不知道如何只获取所有标签上的数字。我需要将其替换为空字符串 ''
。有人可以帮助我并解释我该怎么做吗?
非常非常感谢!!
I have the following problem and I am not really good in regular expressions, so please, could somebody help me out?
<div class="bulletPoints">
<div>
<a href="#autoGeneratedId0" title="test_f01"><img src="../images/test_f01.jpg" alt="test_f01"/>1</a>
<a href="#autoGeneratedId1" title="test_f02"><img src="../images/test_f02.jpg" alt="test_f02"/>2</a>
<a href="#autoGeneratedId2" title="test_f03"><img src="../images/test_f03.jpg" alt="test_f03"/>3</a>
<a href="#autoGeneratedId3" title="test_f04"><img src="../images/test_f04.jpg" alt="test_f04"/>4</a>
<a href="#autoGeneratedId4" title="test_f05"><img src="../images/test_f05.jpg" alt="test_f05"/>5</a>
<a href="#autoGeneratedId5" title="test_f06"><img src="../images/test_f06.jpg" alt="test_f06"/>6</a>
<a href="#autoGeneratedId6" title="test_f07"><img src="../images/test_f07.jpg" alt="test_f07"/>7</a>
<a href="#autoGeneratedId7" title="test_f08"><img src="../images/test_f08.jpg" alt="test_f08"/>8</a>
<a href="#autoGeneratedId8" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>9</a>
<a href="#autoGeneratedId9" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>10</a>
<a href="#autoGeneratedId10" title="test_f09"><img src="../images/test_f09.jpg" alt="test_f09"/>11</a>
<!-- and so on -->
</div>
</div>
I need to replace the plain text string after the image tag inside of each anchor tag. The string is always a number from 0 - 99. The IDs of the anchor tags are auto generated and the title attribute, too. I don't know how to reach only the number on all tags. I need to replace it with an empty string ''
. Could somebody help me and explain how I can do that??
Thank you very very much!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
此操作将仅用图像标签替换图像标签+图像标签后的文本。
Try
This will replace the image tag + text after the image tag with only the image tag.
您可以将
/>[0-9]{,2}<
替换为/><
test with sed:
输出:
you can replace
/>[0-9]{,2}<
with/><
test with sed:
output: