【发布时间】:2012-09-24 00:47:33
【问题描述】:
大约有 100 个文件,我需要遍历每个文件并删除 <style> 和 </style> 之间的所有数据 + 也删除这些标签。
例如
<html>
<head> <title> Example </title> </head>
<style>
p{color: red;
background-color: #FFFF;
}
div {......
...
}
</style>
<body>
<p> hi I'm a paragraph. </p>
</body>
</html>
应该变成
<html>
<head> <title> Example </title> </head>
<body>
<p> hi I'm a paragraph. </p>
</body>
</html>
此外,在某些文件中,样式模式类似于
<style type="text/css"> blah </style>
或
<link rel="stylesheet" type="text/css" href="$url_path/gridsorting.css">
我需要删除所有 3 个模式。我如何在 Perl 中做到这一点?
【问题讨论】:
-
您似乎正在寻求使用正则表达式处理 HTML。那是astonishingly bad idea!
标签: regex perl html-parsing