Z
Z
Zulkund2018-05-08 16:28:08
Java
Zulkund, 2018-05-08 16:28:08

How to write a regular expression to search for html tags in java?

Hello!
Tell me how you can write a regular expression to find the opening and closing html tags. My mows, but I can not understand the reason.
Tag example: <span xml:lang="en" lang="en">, <span>.
The code. args[0] - tag name.

private static boolean containOpenTeg(String substr, String oTag){
       Pattern p = Pattern.compile(oTag);
       Matcher m = p.matcher(oTag);
       return m.find();
   }

   public static void main(String[] args) throws IOException {
       //String oTag = "<"+args[0]+".*?>";
       String oTag = "<"+args[0]+"([^...&&[^ < / ] ] ) * >"; //Открывающий тег
       String cTag = "< / " + args[0] + ">"; // закрывающий тег
       //Регулярки
       Pattern pStart = Pattern.compile(oTag);
       Pattern pStop = Pattern.compile(cTag);

       String unit1 = "< span >";
       String unit2 = "< span xml:lang="en" lang="en\ >";
       String unit3 = "< / span >"";
       String shit = "shit";

       if(containOpenTeg(unit1,oTag)){
           System.out.println("Первый пример");
       }
       if (containOpenTeg(unit2,oTag)){
           System.out.println("Второй пример");
       }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2018-05-08
@aol-nnov

what is the main task? "robbing cows"? take jsoup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question