কম্পিউটার

জাভাতে রেগুলার এক্সপ্রেশন \G মেটাক্যারেক্টার


সাব এক্সপ্রেশন/মেটাচ্যারেক্টার “\G ” যেখানে শেষ ম্যাচটি শেষ হয়েছিল সেই পয়েন্টের সাথে মেলে৷

উদাহরণ

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
   public static void main( String args[] ) {
      String regex = "\\G[0-9]";
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter a string: ");
      String input = sc.nextLine();
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      int count = 0;
      String digits = "";
      System.out.println("Digits in the previous match:");
      while(m.find()) {
         System.out.print(m.group());
         count ++;
      }
      System.out.println();
      System.out.println("Number of matches: "+count);
   }
}

আউটপুট

Enter a string:
555 sample text
Digits in the previous match:
555
Number of matches: 3

  1. জাভাতে রেগুলার এক্সপ্রেশন \A মেটাক্যারেক্টার ব্যাখ্যা কর

  2. নিয়মিত অভিব্যক্তি। (ডট) জাভাতে মেটাক্যারেক্টার

  3. জাভাতে রেগুলার এক্সপ্রেশন $ (ডলার) মেটাক্যারেক্টার

  4. জাভাতে রেগুলার এক্সপ্রেশন ^ (ক্যারেট) মেটাক্যারেক্টার