यह फ्लैग यूनिक्स लाइन्स मोड को सक्षम करता है। यूनिक्स लाइन्स मोड में, केवल '\n' का उपयोग लाइन टर्मिनेटर के रूप में किया जाता है और '\r' को लिटरल कैरेक्टर माना जाता है।
उदाहरण 1 (UNIX_LINES फ्लैग के साथ)
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-YYYY प्रारूप में तिथि स्वीकार करने के लिए रेगुलर एक्सप्रेशन
String regex = "^T.*e";
// पैटर्न ऑब्जेक्ट बनाना
Pattern pattern = Pattern.compile(regex, Pattern.UNIX_LINES);
// मैचर ऑब्जेक्ट बनाना
Matcher matcher = pattern.matcher(input);
int count = 0;
while(matcher.find()) {
count++;
System.out.println(matcher.group());
}
System.out.println("मिलान की संख्या: " + count);
}
}
आउटपुट
This is the first line This is the second line This is the third line मिलान की संख्या: 1
जबकि सामान्य मोड में \r को कैरिज-रिटर्न माना जाता है।
उदाहरण 2 (सामान्य मोड - बिना UNIX_LINES)
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-YYYY प्रारूप में तिथि स्वीकार करने के लिए रेगुलर एक्सप्रेशन
String regex = "^T.*e";
// पैटर्न ऑब्जेक्ट बनाना
Pattern pattern = Pattern.compile(regex);
// मैचर ऑब्जेक्ट बनाना
Matcher matcher = pattern.matcher(input);
int count = 0;
while(matcher.find()) {
count++;
System.out.println(matcher.group());
}
System.out.println("मिलान की संख्या: " + count);
}
}
आउटपुट
This is the first line मिलान की संख्या: 1