title: Getting the data between two square brackets in java from a digital certificate?
body: <pre><code>Pattern patronValidity = Pattern.compile("Validity: \\[(.*?)\\]");
              Matcher matcherValidity = patronValidity.matcher(strCert);
              if(matcherValidity.find()){
                  System.out.println(matcherValidity.group(1));
              }
  </code></pre>
  
  <p>I'm using that to scan a file but it returns no matches. Strangely, the next one does return something, but it's wrong since the left bracket remains in the info.</p>
  
  <pre><code>Pattern patronValidity = Pattern.compile("Validity: (\\[[^]]*)");
              Matcher matcherValidity = patronValidity.matcher(strCert);
              if(matcherValidity.find()){
                  System.out.println(matcherValidity.group(1));
              }
  </code></pre>
  
  <p>This is the value I'm trying to match.</p>
  
  <p>It goes from this as in the file:</p>
  
  <pre><code>Validity: [From: Thu Aug 21 10:22:08 CDT 2008,
                 To: Sat Aug 21 10:22:08 CDT 2010]
  </code></pre>
  
  <p>To this as in the output from the second function:</p>
  
  <pre><code>[From: Thu Aug 21 10:22:08 CDT 2008,
                 To: Sat Aug 21 10:22:08 CDT 2010
  </code></pre>
  
  <p>The first function doesn't match anything.</p>