মাল্টিলাইন মোড সক্ষম করে৷
৷সাধারণভাবে, ^ এবং $ মেটা অক্ষরগুলি প্রদত্ত ইনপুটটির শুরু এবং শেষের সাথে নির্দিষ্ট অক্ষরগুলির সাথে মেলে, তাতে লাইনের সংখ্যা নির্বিশেষে৷
উদাহরণ 1
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MULTILINE_Example {
public static void main( String args[] ) {
//String regex = "(^This)";//.*t$)";
String input = "2234 This is a sample text\n"
+ "1424 This second 2335 line\n"
+ "This id third 455 line\n"
+ "Welcome to Tutorialspoint\n";
Pattern pattern = Pattern.compile("^([0-9]+).*");//, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(input);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
} আউটপুট
2234
আপনি যখন কম্পাইল() পদ্ধতিতে ফ্ল্যাগ মান হিসাবে এটি ব্যবহার করেন, তখন পুরো ইনপুট ক্রমটিকে একটি একক লাইন হিসাবে বিবেচনা করা হবে এবং মেটা অক্ষর ^ এবং $ প্রদত্ত ইনপুট ক্রমটির শুরু এবং শেষের সাথে মেলে৷
উদাহরণ 2
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MULTILINE_Example {
public static void main( String args[] ) {
//String regex = "(^This)";//.*t$)";
String input = "2234 This is a sample text\n"
+ "1424 This second 2335 line\n"
+ "This id third 455 line\n"
+ "Welcome to Tutorialspoint\n";
Pattern pattern = Pattern.compile("^([0-9]+).*", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(input);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
} আউটপুট
2234 1424