Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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中只解析带有正则表达式的HTML标记而不使用jsoup_Java_Html_Parsing_Html Parsing - Fatal编程技术网

如何在java中只解析带有正则表达式的HTML标记而不使用jsoup

如何在java中只解析带有正则表达式的HTML标记而不使用jsoup,java,html,parsing,html-parsing,Java,Html,Parsing,Html Parsing,大家好,我只需要用正则表达式解析HTML标记,剩下不带jsoup的非HTML标记 比如说 <h1> i love india <\h1> <xyz> name <\xyz> <html> hey i won! <\html> <syd> like it <\syd> <<<<<< <br> love you <br> >>&g

大家好,我只需要用正则表达式解析HTML标记,剩下不带jsoup的非HTML标记

比如说

<h1> i love india <\h1>
<xyz> name <\xyz>
<html> hey i won! <\html>
<syd> like it <\syd>
<<<<<<
<br> love you <br>  
>>>>>>>>

我试了很多,但没有得到确切的答案,没有人能帮我摆脱困境。提前谢谢

使用正则表达式删除所有标记:

s.replaceAll("<[^>]*>", "");
s.replaceAll(“]*>”,“”);
尝试以下操作:

        String[] array = { "<h1> i love india <\h1>",
                           "<xyz> name <\xyz>",
                           "<html> hey i won! <\html>",
                           "<syd> like i`enter code here`t <\syd>"
                        };
    Pattern pattern = Pattern.compile(">((.[^><]+))<");
    for (String str : array ) {
        Matcher m = pattern.matcher(str);
        if(m.find()) 
          System.out.println(m.group(1));
        else
          System.out.println("none");
    }
String[]数组={“我爱印度”,
“姓名”,
“嘿,我赢了!”,
“就像我在这里输入代码一样”
};

Pattern=Pattern.compile(“>()。[^>谢谢你的评论,它删除了所有的标签,但我只想删除html标签…对于非html标签,它将不显示任何标签。然后你需要指定所有可能的html标签,并为每个案例做正确的事情是否有其他方法…jaudothanks moti…你能解释一下m.group将如何工作…我对此感到困惑…用于考试我有一个字符串,比如string=“我喜欢我自己,如果我喜欢m.group(),答案是什么,m.group(1)和m.group(2)你能解释一下正则表达式是如何工作的吗…它如何只知道html标记如果你看模式:(“>(.[^>
        String[] array = { "<h1> i love india <\h1>",
                           "<xyz> name <\xyz>",
                           "<html> hey i won! <\html>",
                           "<syd> like i`enter code here`t <\syd>"
                        };
    Pattern pattern = Pattern.compile(">((.[^><]+))<");
    for (String str : array ) {
        Matcher m = pattern.matcher(str);
        if(m.find()) 
          System.out.println(m.group(1));
        else
          System.out.println("none");
    }