এই পতাকাটি ইউনিক্স লাইন মোড সক্ষম করে। ইউনিক্স লাইন মোডে, লাইন টার্মিনেটর হিসেবে শুধুমাত্র '\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