1
안녕하세요 저는 다음 코드가있는 정규식을 사용하여 문자열의 구문을 검색하려고합니다. 모든 두 단어 구문을 찾지 못하는 것 같습니다.자바에서 사용자 정규 표현식을 찾으려면
public static void main(String[] args) {
String inputText = "test and test Test hello hello hello test test hello hello ";
//Pattern pattern = Pattern.compile("((\\w{3,}?)\\W(\\w{3,}?)\\W).*\\2\\W\\3", Pattern.CASE_INSENSITIVE);
Pattern twoWordPrasePattern = Pattern.compile("(([a-zA-Z]{3,})\\W([a-zA-Z]{3,})\\W).*\\2\\W\\3", Pattern.CASE_INSENSITIVE);
Matcher matcher = twoWordPrasePattern.matcher(inputText);
while (matcher.find()) {
System.out.println(inputText.substring(matcher.start(), matcher.end()));
System.out.println(matcher.group(1));
}
}
안녕하세요 hello 그룹이 퇴장하지 않는 이유는 무엇입니까? 도움을 주신 데 감사드립니다. 어떻게 모든 문구를 찾기 위해 패턴을 바꿀 수 있습니까? Richard
감사합니다 ruakh, 그게 어떻게 지금 모든 문구를 찾기 위해 패턴을 변경할 수 있습니다 설명 – Richard