কম্পিউটার টিউটোরিয়াল

জাভায় Pattern UNIX_LINES ফিল্ড উদাহরণসহ ব্যাখ্যা

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

উদাহরণ ১

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";
        
        // MM-DD-YYY ফরম্যাটে তারিখ গ্রহণের রেগুলার এক্সপ্রেশন
        String regex = "^T.*e";
        
        // Pattern অবজেক্ট তৈরি
        Pattern pattern = Pattern.compile(regex, Pattern.UNIX_LINES);
        
        // Matcher অবজেক্ট তৈরি
        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 ক্যারেজ-রিটার্ন হিসেবে বিবেচিত হয়।

উদাহরণ ২

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";
        
        // MM-DD-YYY ফরম্যাটে তারিখ গ্রহণের রেগুলার এক্সপ্রেশন
        String regex = "^T.*e";
        
        // Pattern অবজেক্ট তৈরি
        Pattern pattern = Pattern.compile(regex);
        
        // Matcher অবজেক্ট তৈরি
        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. জাভায় Pattern LITERAL ফিল্ড উদাহরণসহ ব্যাখ্যা

  2. জাভায় Pattern DOTALL ফিল্ড উদাহরণসহ ব্যাখ্যা

  3. জাভায় Pattern COMMENTS ফিল্ড উদাহরণসহ ব্যাখ্যা

  4. জাভায় Pattern CANON_EQ ফিল্ড উদাহরণসহ ব্যাখ্যা