Regular expression for file extensions in Java
<p>I am trying to write a simple regular expression to identify all filenames in a list which end with ".req.copied" extension. The code I am using is given below</p>

<pre><code>public class Regextest {
 public static void main(String[] args) {
    // TODO Auto-generated method stub
 String test1=new String("abcd.req.copied");
  if(test1.matches("(req.copied)?")) {
     System.out.println("Matches");
    }
  else
     System.out.println("Does not Match");
    }

 }
</code></pre>

<p>The regex tests ok in online regex testers but does not function in the program. I have tried multiple combinations (like splitting req and copied into two regexes, or literal matching of the dot character) but nothing works (even the simplest regex of (reg)? returned a "Does not Match" output). Please let me know how to tackle this.</p>