Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式替换java中的所有_Java_Regex - Fatal编程技术网

正则表达式替换java中的所有

正则表达式替换java中的所有,java,regex,Java,Regex,我有一个包含一些HTML内容的字符串。我想用java中的正则表达式替换所有HTML标记及其内容 因此,例如等应该删除 我试过了 str=str.replaceAll("<\\w*>",""); str=str.replaceAll(“,”); 但它只替换字符串中的第一个匹配项 如何替换字符串中出现的所有此类内容。 谢谢你能试试这个吗 str = str.replaceAll("<[^>]*>", ""); str=str.replaceAll(“]*>”,“”

我有一个包含一些HTML内容的字符串。我想用java中的正则表达式替换所有HTML标记及其内容

因此,例如
等应该删除

我试过了

str=str.replaceAll("<\\w*>","");
str=str.replaceAll(“,”);
但它只替换字符串中的第一个匹配项

如何替换字符串中出现的所有此类内容。 谢谢你能试试这个吗

str = str.replaceAll("<[^>]*>", "");
str=str.replaceAll(“]*>”,“”);
你能试试这个吗

str = str.replaceAll("<[^>]*>", "");
str=str.replaceAll(“]*>”,“”);

可能重复的@TanujWadhwa的可能重复匹配左角括号。然后匹配0个或多个非直角括号。。。换句话说,匹配到但不包括第一个直角括号(因为“是否可以跳过标记,例如,
并替换其余的。@TanujWadhwa匹配一个左角括号。然后匹配0个或多个非右角括号…换句话说,匹配到但不包括第一个右角括号(因为”是否可以跳过标签,例如
并替换其余标签。