Pattern ক্লাসের DOTALL ফিল্ড ডটল মোড (dotall mode) সক্ষম করে। ডিফল্টভাবে, রেগুলার এক্সপ্রেশন-এ "." মেটা ক্যারেক্টার লাইন টার্মিনেটর ব্যতীত সব ক্যারেক্টার মিলায়।
উদাহরণ ১
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
ডটল মোডে এটি লাইন টার্মিনেটরসহ সব ক্যারেক্টার মিলায়।
অন্য কথায়, আপনি যখন compile() মেথডে এই ফ্ল্যাগ মান হিসেবে ব্যবহার করেন, "." মেটা ক্যারেক্টার লাইন টার্মিনেটরসহ সব ক্যারেক্টার মিলায়।
উদাহরণ ২
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