title: Java regex: how to select words starting with a specific letter and is x number of characters long?
body: <p>This is the code I wrote that selects all names starting from A:</p>
  
  <pre><code>String longString = "Amal Kamal Jamal Amitha Farook Amani Tom Adele George Ariana";
  String pattern = "(?i)(\\s|^)[a][A-Za-z]+(\\s|$)";
  Pattern checkRegex = Pattern.compile(pattern);
  Matcher regexMatcher = checkRegex.matcher(longString);
  while (regexMatcher.find()) {
      System.out.println(regexMatcher.start() + " : " + regexMatcher.group());
  }
  </code></pre>
  
  <p>Output is as expected</p>
  
  <pre><code>0 : Amal 
  16 :  Amitha 
  30 :  Amani 
  40 :  Adele 
  53 :  Ariana
  </code></pre>
  
  <p>Now I want to select names that are at least 5 characters long. So the expected output is: Amitha, Adele, Ariana.</p>
  
  <p>When I type this only Ariana is returned. And I can't understand why.</p>
  
  <pre><code>String pattern = "(?i)(\\s|^)[a][A-Za-z]+(\\s|$){5,}";
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>53 :  Ariana
  </code></pre>
  
  <p>If I put a bracket around the whole expression (to say that this expression should be 5 characters long) Then output is nothing</p>
  
  <pre><code>String pattern = "(?i)((\\s|^)[a][A-Za-z]+(\\s|$)){5,}";
  </code></pre>
  
  <p>What is the correct way of writing this?</p>