প্যাটার্নের লিটারেল পার্সিং (literal parsing) সক্ষম করে। এই মোডে, এস্কেপ সিকোয়েন্স এবং মেটা-ক্যারেক্টারসহ সমস্ত ক্যারেক্টারের কোনো বিশেষ অর্থ নেই, এগুলো লিটারেল ক্যারেক্টার হিসেবে বিবেচিত হয়।
উদাহরণস্বরূপ, সাধারণত আপনি যদি দেয়া ইনপুট টেক্সট-এ রেগুলার এক্সপ্রেশন "^This" খুঁজেন তবে এটি "This" শব্দ দিয়ে শুরু হওয়া লাইনগুলো মিলাবে।
উদাহরণ
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\n"
+ "This is the second line\n"
+ "^This is the third line";
// MM-DD-YYY ফরম্যাটে তারিখ গ্রহণের রেগুলার এক্সপ্রেশন
String regex = "^This";
// Pattern অবজেক্ট তৈরি
Pattern pattern = Pattern.compile(regex, Pattern.LITERAL);
// 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 Number of matches: 1
লিটারেল মোডে, মেটা ক্যারেক্টার "^" এর কোনো অর্থ নেই এবং রেগুলার এক্সপ্রেশন "^This" সঠিক শব্দটি মিলায়।
উদাহরণ
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\n"
+ "This is the second line\n"
+ "^This is the third line";
// MM-DD-YYY ফরম্যাটে তারিখ গ্রহণের রেগুলার এক্সপ্রেশন
String regex = "^This";
// Pattern অবজেক্ট তৈরি
Pattern pattern = Pattern.compile(regex, Pattern.LITERAL);
System.out.println("Usually it is printed as: \n" + input);
// 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);
}
}
আউটপুট
Usually it is printed as: This is the first line This is the second line ^This is the third line ^This Number of matches: 1