কম্পিউটার

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


এই পতাকাটি ইউনিক্স লাইন মোড সক্ষম করে। ইউনিক্স লাইন মোডে, লাইন টার্মিনেটর হিসেবে শুধুমাত্র '\n' ব্যবহার করা হয় এবং '\r' কে আক্ষরিক অক্ষর হিসেবে ধরা হয়।

উদাহরণ 1

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LTERAL_Example {
   public static void main(String[] args) {
      String input = "This is the first line\r"
         + "This is the second line\r"
         + "This is the third line\r";
      //Regular expression to accept date in MM-DD-YYY format
      String regex = "^T.*e";
      //Creating a Pattern object
      Pattern pattern = Pattern.compile(regex, Pattern.UNIX_LINES);
      //Creating a Matcher object
      Matcher matcher = pattern.matcher(input);
      int count = 0;
      while(matcher.find()) {
         count++;
         System.out.println(matcher.group());
      }
      System.out.println("Number of matches: "+count);
   }
}

আউটপুট

This is the first line
This is the second line
This is the third line
Number of matches: 1

যেখানে সাধারণ মোডে \r কে ক্যারেজ-রিটার্ন হিসাবে ধরা হয়।

উদাহরণ 2

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LTERAL_Example {
   public static void main(String[] args) {
      String input = "This is the first line\r"
         + "This is the second line\r"
         + "This is the third line\r";
      //Regular expression to accept date in MM-DD-YYY format
      String regex = "^T.*e";
      //Creating a Pattern object
      Pattern pattern = Pattern.compile(regex);
      //Creating a Matcher object
      Matcher matcher = pattern.matcher(input);
      int count = 0;
      while(matcher.find()) {
         count++;
         System.out.println(matcher.group());
      }
      System.out.println("Number of matches: "+count);
   }
}

আউটপুট

This is the first line
Number of matches: 1

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

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

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

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