why java regex matches only single character code example

Example 1: regex get string between quotes java

Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(line);
while (m.find()) {
  System.out.println(m.group(1));
}

Example 2: Regex split java

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

   public static void main(String[] args) {

      String str = "a d, m, i.n";
      String delimiters = "\\s+|,\\s*|\\.\\s*";

      // analyzing the string 
      String[] tokensVal = str.split(delimiters);

      // prints the number of tokens
      System.out.println("Count of tokens = " + tokensVal.length);
    
      for(String token : tokensVal) {
         System.out.print(token);
      } 
   }
}

Tags:

Java Example