Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 正则表达式匹配打开的标签,XHTML 自包含标签除外
如何用空格替换 < > 和标签本身之间的所有内容?
例子:
<span class="bold">asdfsdfsda<br />sadfsdfsdf</span>
输出:
asdfsdfsda sadfsdfsdf
不要使用正则表达式解析 HTML。如果这是在一次受控的情况下,那么这样做:
这里是红宝石。根据您的工具更改它。
myline = '<span class="bold">asdfsdfsda<br />sadfsdfsdf</span>' myline.gsub(/<[^<]*>/," ")