কম্পিউটার

উদাহরণ সহ জাভাতে DOTALL ক্ষেত্রের প্যাটার্ন


প্যাটার্ন শ্রেণীর DOTALL ক্ষেত্রটি ডটল মোড সক্ষম করে। ডিফল্টরূপে, "।" রেগুলার এক্সপ্রেশনে মেটা ক্যারেক্টার লাইন টার্মিনেটর ছাড়া সব অক্ষরের সাথে মেলে।

উদাহরণ 1

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DOTALL_Example {
   public static void main( String args[] ) {
      String regex = ".";
      String input = "this is a sample \nthis is second line";
      Pattern pattern = Pattern.compile(regex);
      Matcher matcher = pattern.matcher(input);
      int count =0;
      while(matcher.find()) {
         count++;
         System.out.print(matcher.group());
      }
      System.out.println();
      System.out.println("Number of new line characters: \n"+count);
   }
}

আউটপুট

this is a sample this is second line
Number of new line characters:
36

ডট অল মোডে এটি লাইন টার্মিনেটর সহ সমস্ত অক্ষরের সাথে মেলে।

অন্য কথায় আপনি যখন কম্পাইল() পদ্ধতিতে ফ্ল্যাগ মান হিসাবে এটি ব্যবহার করেন, তখন "।" মেটা অক্ষর লাইন টার্মিনেটর সহ সমস্ত অক্ষরের সাথে মেলে।

উদাহরণ 2

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DOTALL_Example {
   public static void main( String args[] ) {
      String regex = ".";
      String input = "this is a sample \nthis is second line";
      Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
      Matcher matcher = pattern.matcher(input);
      int count = 0;
      while(matcher.find()) {
         count++;
         System.out.print(matcher.group());
      }
      System.out.println();
      System.out.println("Number of new line characters: \n"+count);
   }
}

আউটপুট

this is a sample
this is second line
Number of new line characters:
37

  1. উদাহরণ সহ জাভাতে মাল্টিলাইন ক্ষেত্র প্যাটার্ন

  2. উদাহরণ সহ জাভাতে প্যাটার্ন লিটারাল ফিল্ড

  3. উদাহরণ সহ জাভাতে প্যাটার্ন মন্তব্য ক্ষেত্র

  4. উদাহরণ সহ জাভাতে প্যাটার্ন CANON_EQ ক্ষেত্র