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 Example {
public static void main( String args[] ) {
String regex = "you$";
//Reading input from user
Scanner sc = new Scanner(System.in);
String input = "Hello how are you";
//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();
int end = res.end();
System.out.println(end);
}
} আউটপুট
Enter input text: hello how are you Match found 17