কম্পিউটার

উদাহরণ সহ জাভাতে MatchResult start() পদ্ধতি।


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 StartExample {
   public static void main(String args[]) {
      //Reading String from user
      System.out.println("Enter a String");
      Scanner sc = new Scanner(System.in);
      String input = sc.nextLine();
      String regex = "\\W";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex);
      //Retrieving the matcher object
      Matcher matcher = pattern.matcher(input);
      if(matcher.find()) {
         System.out.println("Match occurred");
      }else {
         System.out.println("Match not occurred");
      }
      //Retrieving the MatchResult object
      MatchResult res = matcher.toMatchResult();
      int start = res.start();
      System.out.println(start);
   }
}

আউটপুট

Enter a String
This * is # sample % text with & non word characters
Match occurred
4

  1. উদাহরণ সহ জাভাতে ম্যাচার গ্রুপ() পদ্ধতি

  2. উদাহরণ সহ জাভাতে ম্যাচার রিসেট() পদ্ধতি

  3. উদাহরণ সহ জাভাতে ম্যাচার প্যাটার্ন() পদ্ধতি

  4. উদাহরণ সহ জাভাতে ম্যাচার স্টার্ট() পদ্ধতি