예를 들어 새 클래스를 감지하는 정규식을 만들려고합니다.
public interface IGame {
또는
private class Game {
이것은 내가 지금까지 가지고 있지만 감지하지 못합니다.
(line.matches("(public|protected|private|static|\\s)"+"(class|interface|\\s)"+"(\\w+)"))
누구든지 나에게 몇 가지 지침을 줄 수 있습니까?
두 유형의 문자열 형식과 일치하도록 정규식을 아래와 같이 변경하십시오.
line.matches("(?:public|protected|private|static)\\s+(?:class|interface)\\s+\\w+\\s*\\{");
예:
String s1 = "public interface IGame {";
String s2 = "private class Game {";
System.out.println(s1.matches("(?:public|protected|private|static)\\s+(?:class|interface)\\s+\\w+\\s*\\{"));
System.out.println(s2.matches("(?:public|protected|private|static)\\s+(?:class|interface)\\s+\\w+\\s*\\{"));
산출:
true
true
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다