title: Using multiple regex to scan a file
body: <p>I have some code that takes in a URL, reads through the file and searches for Strings that match a given regular expression and adds any matches to an arrayList until it reaches the end of the file. How can I modify my code so that while reading through the file, I can check for other Strings matching other regular expressions on the same pass rather than having to read the file multiple times checking for each different regex?</p>
  
  <pre><code>    //Pattern currently being checked for
      Pattern name = Pattern.compile("&lt;a id=.dg__ct(.+?)_hpl1.&gt;(.+?)&lt;/a&gt;");
  
      //Pattern I want to check for as well, currently not implemented
      Pattern date = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{4}");
  
      Matcher m;
      InputStream inputStream = null;
      arrayList = new ArrayList&lt;String&gt;();
      try {
          URL url = new URL(
                  "URL to be read");
          inputStream = (InputStream) url.getContent();
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          InputStreamReader isr = new InputStreamReader(inputStream);
          BufferedReader buf = new BufferedReader(isr);
          String str = null;
          String s = null;
  
          try {
              while ((str = buf.readLine()) != null) {
  
                  m = name.matcher(str);
                  while(m.find()){
                      s = m.group();
                      arrayList.add(s);
                  }
  
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>