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

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

Pattern ক্লাসের CANON_EQ ফিল্ড দুটি ক্যারেক্টার তখনই মিলায় যখন সেগুলো ক্যানোনিক্যালি সমান (canonically equal) হয়। আপনি যখন compile() মেথডে এই ফ্ল্যাগ মান হিসেবে ব্যবহার করেন, দুটি ক্যারেক্টার মিলবে যদি এবং কেবল যদি তাদের পূর্ণ ক্যানোনিক্যাল ডিকম্পোজিশন (full canonical decomposition) সমান হয়।

যেখানে ক্যানোনিক্যাল ডিকম্পোজিশন ইউনিকোড টেক্সট নর্মালাইজেশন ফর্মের একটি।

উদাহরণ ১

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CANON_EQ_Example {
    public static void main(String args[]) {
        String regex = "b\u0307";
        
        // রেগুলার এক্সপ্রেশন কম্পাইল
        Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ);
        
        // Matcher অবজেক্ট পাওয়া
        Matcher matcher = pattern.matcher("\u1E03");
        
        if(matcher.matches()) {
            System.out.println("Match found");
        } else {
            System.out.println("Match not found");
        }
    }
}

আউটপুট

Match found

উদাহরণ ২

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CANON_EQ_Example {
    public static void main(String args[]) {
        String regex = "a\u030A";
        
        // রেগুলার এক্সপ্রেশন কম্পাইল
        Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ);
        
        // Matcher অবজেক্ট পাওয়া
        String[] input = {"\u00E5", "a\u0311", "a\u0325", "a\u030A", "a\u1E03", "a\uFB03"};
        
        for (String ele : input) {
            Matcher matcher = pattern.matcher(ele);
            if(matcher.matches()) {
                System.out.println(ele + " is a match for " + regex);
            } else {
                System.out.println(ele + " is not a match for " + regex);
            }
        }
    }
}

আউটপুট

å is a match for å
ȃ is not a match for å
ḁ is not a match for å
å is a match for å
aḃ is not a match for å
affi is not a match for å
  1. জাভায় Pattern MULTILINE ফিল্ড উদাহরণসহ ব্যাখ্যা

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

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

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