কম্পিউটার

উদাহরণ সহ জাভাতে ম্যাচার খুঁজুন() পদ্ধতি


java.util.regex.Matcher ক্লাস একটি ইঞ্জিনের প্রতিনিধিত্ব করে যা বিভিন্ন ম্যাচ অপারেশন করে। এই ক্লাসের জন্য কোন কনস্ট্রাক্টর নেই আপনি java.util.regex.Pattern ক্লাসের matches() পদ্ধতি ব্যবহার করে এই ক্লাসের একটি অবজেক্ট তৈরি/প্রাপ্ত করতে পারেন।

find() এই ক্লাসের পদ্ধতিটি বর্তমান ম্যাচার অবজেক্টের সাথে মেলে পরবর্তী পরবর্তী ইনপুট খুঁজে বের করার চেষ্টা করে, ম্যাচের ক্ষেত্রে এই পদ্ধতিটি সত্য দেখায় অন্যথায় এটি মিথ্যা ফেরত দেয়।

উদাহরণ

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FindExample {
   public static void main( String args[] ) {
      //Reading string value
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter input string");
      String input = sc.nextLine();
      //Regular expression to find digits
      String regex = "(\\D)";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex);
      //Retrieving the matcher object
      Matcher matcher = pattern.matcher(input);
      //verifying whether match occurred
      if(matcher.find()) {
         System.out.println("Given string contain non-digit characters");
      } else {
         System.out.println("Given string does not contain non-digit characters");
      }
   }
}

আউটপুট

Enter input string
11245#
Given string contain non-digit characters

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

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

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

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