English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
모드의 글자 분석을 활성화합니다. 여기서 모든 문자(탈출 시퀀스와 문자열 표기기 포함)는 특별한 의미가 없으며, 글자로 간주됩니다.
예를 들어, 일반적으로, 주어진 입력 텍스트에서 정규 표현식 “^ This”를 검색하면, 그것은 단어로 시작되는“This”시작 행
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\n" + "This is the second line\n" + "^This is the third line"; //정규 표현식은 MM-DD-YYY 형식은 날짜를 받아들입니다 String regex = "^This"; //Pattern 객체 생성 Pattern pattern = Pattern.compile(regex, Pattern.LITERAL); //Matcher 객체 생성 Matcher matcher = pattern.matcher(input); int count = 0; while(matcher.find()) { count++; System.out.println(matcher.group()); } System.out.println("Number of matches: ");+count); } }
출력 결과
^This 매치 횟수: 1
문자 모드에서, 문자열 표기기 "^"은 의미가 없으며, 정규 표현식 "^ This"는 정확한 단어와 일치합니다.
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\n" + "This is the second line\n" + "^This is the third line"; //정규 표현식은 MM-DD-YYY 형식은 날짜를 받아들입니다 String regex = "^This"; //Pattern 객체 생성 Pattern pattern = Pattern.compile(regex, Pattern.LITERAL); System.out.println("Usually it is printed as: "+input); //Matcher 객체 생성 Matcher matcher = pattern.matcher(input); int count = 0; while(matcher.find()) { count++; System.out.println(matcher.group()); } System.out.println("Number of matches: ");+count); } }
출력 결과
보통은 다음과 같이 출력됩니다: This is the first line This is the second line ^This is the third line ^This 매치 횟수: 1