Java 使用正则表达式从文本文件中删除样式标记

Java 使用正则表达式从文本文件中删除样式标记,java,regex,Java,Regex,我需要从文本文件中删除样式标记 我尝试了以下代码 String text = readFile("E:/textwithstyletags.txt"); retVal = text.replaceAll("<style(.+?)</style>", ""); String text=readFile(“E:/textwithstyletags.txt”); retVal=text.replaceAll(“您可以使用[\s\s]代替正则表达式中的” i、 e: retVal=t

我需要从文本文件中删除样式标记

我尝试了以下代码

String text = readFile("E:/textwithstyletags.txt");
retVal = text.replaceAll("<style(.+?)</style>", "");
String text=readFile(“E:/textwithstyletags.txt”);

retVal=text.replaceAll(“您可以使用
[\s\s]
代替正则表达式中的

i、 e:

retVal=text.replaceAll(“试试这个正则表达式:

retVal  = text.replaceAll("(?i)<style.*?>.*?</style>", "");
retVal=text.replaceAll(“(?i.*?”,”);
在旁注中,您可以查看,这是一个用于HTML操作的java库。

您可以使用

此表达式在上进行了测试

模式:

<style((.|\n|\r)*?)<\/style>    

可能相关?请发布完整的正则表达式expression@user3264864使用上面的表达式有效的转义序列使用双反斜杠
\\w
\\w
@user32648644i这样,处理所有内容不贪婪,不区分大小写,没有混乱,没有麻烦。尽管我认为您需要添加s标志(点匹配所有)处理打开和关闭标记之间的换行。例如:
retVal=text.replaceAll(“(?is)。*?”,”);
retVal  = text.replaceAll("(?i)<style.*?>.*?</style>", "");
retVal = text.replaceAll("<style[\\w\\W]+?</style>", "");
<style((.|\n|\r)*?)<\/style>    
String text = readFile("E:/textwithstyletags.txt");
retVal = text.replaceAll("<style((.|\\n|\\r)*?)<\\/style>", "");