English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
تفعيل نمط الخطوط المتعددة.
عادة، العلامات النصية ^ و $ ستقوم بمطابقة البداية والنهاية من الدخول المحدد مع الأحرف المحددة، بغض النظر عن عدد الأطراف.
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 w3codebox\n"; مثال pattern pattern = Pattern.compile("^([0-9]+).*");, Pattern.MULTILINE); Matcher matcher = pattern.matcher(input); while(matcher.find()) { System.out.println(matcher.group(1)); } } }
نتائج الخروج
2234
عندما يتم استخدام هذا القيمةcompile()
عندما يتم استخدام هذا المفتاح، يتم اعتبار جميع السلسلة المدخلة كخط واحد، وتُناسب الحروف الموجودة في بداية ونهاية السلسلة المدخلة.
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 w3codebox\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