Pattern 클래스의 DOTALL 필드 dotall 모드를 활성화합니다. 기본적으로 "." 정규식의 메타 문자는 줄 종결자를 제외한 모든 문자와 일치합니다.
예시 1
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DOTALL_Example {
public static void main( String args[] ) {
String regex = ".";
String input = "this is a sample \nthis is second line";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
int count =0;
while(matcher.find()) {
count++;
System.out.print(matcher.group());
}
System.out.println();
System.out.println("Number of new line characters: \n"+count);
}
} 출력
this is a sample this is second line Number of new line characters: 36
전체 점 모드에서는 줄 종결자를 포함한 모든 문자와 일치합니다.
즉, 이것을 compile() 메소드의 플래그 값으로 사용하면 "." 메타 문자는 줄 종결자를 포함한 모든 문자와 일치합니다.
예시 2
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DOTALL_Example {
public static void main( String args[] ) {
String regex = ".";
String input = "this is a sample \nthis is second line";
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
Matcher matcher = pattern.matcher(input);
int count = 0;
while(matcher.find()) {
count++;
System.out.print(matcher.group());
}
System.out.println();
System.out.println("Number of new line characters: \n"+count);
}
} 출력
this is a sample this is second line Number of new line characters: 37