title: Java Regex : How to match one or more space characters
body: <p>How do you match more than one space character in Java regex?</p>
  
  <p>I have a regex I am trying to match. The regex fails when I have two or more space characters.</p>
  
  <pre><code>public static void main(String[] args) { 
      String pattern = "\\b(fruit)\\s+([^a]+\\w+)\\b"; //Match 'fruit' not followed by a word that begins with 'a'
      String str = "fruit apple"; //One space character will not be matched
      String str_fail = "fruit  apple"; //Two space characters will be matched
      System.out.println(preg_match(pattern,str)); //False (Thats what I want)
      System.out.println(preg_match(pattern,str_fail)); //True (Regex fail)
  }
  
  public static boolean preg_match(String pattern,String subject) {
      Pattern regex = Pattern.compile(pattern);
      Matcher regexMatcher = regex.matcher(subject);
      return regexMatcher.find();
  }
  </code></pre>