java - determining if an array list beginning and ending and displaying everything in between -


i'm trying filter through array list contains content of url stored in: (list<string> quotes = new arraylist<>();) and, display result every thing in between <pre> </pre> tags (all quotes placed between these 2 tags). figured out printing part there method in java allows filter array list specified? thanks

more detail:

so have normal html file contains kinds of tags. lets scan page , store text in string array. want display content between <pre></pre> tags , not rest. hope helps

here how text stored:

list<string> cookies = new arraylist<>();     public void init() throws servletexception      {         try          {          url url = new url(" http://fortunes.cat-v.org/openbsd/");              bufferedreader in = new bufferedreader(new inputstreamreader(url.openstream()));          string line ;             while((line = in.readline()) != null)            {           cookies.add(line);           //line = in.readline();            }          in.close();       }      catch (java.net.malformedurlexception e)      {       system.out.println("malformed url: " + e.getmessage());     }     catch (ioexception e)      {       system.out.println("i/o error: " + e.getmessage());     }  } 

use regular expression, here's full working example

import java.util.arraylist; import java.util.list; import java.util.regex.matcher; import java.util.regex.pattern;     public class test {     public static void main(string [] args){         //this list supposed filled values         list<string> quotes = new arraylist<string>();          for(string quote:quotes){             pattern pattern = pattern.compile(".*?<pre>(.*?)</pre>.*?");             matcher m = pattern.matcher(quote);             while(m.find()){                 string result = m.group(1);                 system.out.println(result);             }         }   } 

}


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -