English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Habilitar el modo de múltiples líneas.
Por lo general, los caracteres meta ^ y $ coinciden con el principio y el final de la entrada especificada, independientemente del número de líneas.
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 "Este es un texto de ejemplo\n" + "1424 Este segundo 2335 line\n" + "Este id third" 455 line\n" + "Bienvenido a w"3codebox\n" Pattern pattern = Pattern.compile("^([0-9]+.*");//, Pattern.MULTILINE); Matcher matcher = pattern.matcher(input); System.out.println(matcher.group(1)); } } }
Resultados de salida
2234
al usar este valor comocompile()
Cuando se usa este valor como
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 "Este es un texto de ejemplo\n" + "1424 Este segundo 2335 line\n" + "Este id third" 455 line\n" + "Bienvenido a w"3codebox\n" Pattern pattern = Pattern.compile("^([0-9]+.*", Pattern.MULTILINE); Matcher matcher = pattern.matcher(input); System.out.println(matcher.group(1)); } } }
Resultados de salida
2234 1424