java.util.regex.MatcheResult ইন্টারফেস একটি ম্যাচের ফলাফল পুনরুদ্ধার করার পদ্ধতি প্রদান করে।
আপনি toMatchResult() ব্যবহার করে এই ইন্টারফেসের একটি বস্তু পেতে পারেন ম্যাচারের পদ্ধতি ক্লাস এই পদ্ধতিটি একটি MatchResult অবজেক্ট প্রদান করে যা বর্তমান ম্যাচারের ম্যাচের অবস্থাকে উপস্থাপন করে।
গোষ্ঠী() এই ইন্টারফেসের পদ্ধতিটি শেষ ম্যাচে প্রদত্ত ইনপুট ক্রম থেকে মিলিত সাবস্ট্রিংকে উপস্থাপন করে একটি স্ট্রিং মান প্রদান করে।
উদাহরণ
import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GroupExample {
public static void main( String args[] ) {
String regex = "(.*)(\\d+)(.*)";
//Reading input from user
Scanner sc = new Scanner(System.in);
System.out.println("Enter input text: ");
String input = sc.nextLine();
//Instantiating the Pattern class
Pattern pattern = Pattern.compile(regex);
//Instantiating the Matcher class
Matcher matcher = pattern.matcher(input);
//verifying whether a match occurred
if(matcher.find()) {
System.out.println("Match found");
}
MatchResult res = matcher.toMatchResult();
String matchedData = res.group();
System.out.println(matchedData);
}
} আউটপুট
Enter input text: This is a sample Text, 123 Match found This is a sample Text, 123