것은 그래서에 포함하는 문자와 일치하지 않을 (단어 경계로 둘러싸인 (대문자 또는 소문자) 어떤 GCAT 문자 순서에 일치하는이 패턴 "\\b([GCATgcat]+)\\b
"를보십시오 "카탈로그"와 같은 다른 문자열). 샘플 파일에서이 정규식을 반복적으로 스캔하면 각 시퀀스가 추출됩니다.
여기 샘플 파일에 대한 작업 예제 : 정규식 슈퍼 마법사 아닌 사람들 우리 모두
// Locate the substring between "ORIGIN" and "//" in the file.
String fileContents = getSampleFileContents();
int indexOfOrigin = fileContents.indexOf("ORIGIN");
String pertinentSection = fileContents.substring(
indexOfOrigin, fileContents.indexOf("//", indexOfOrigin));
// Search for sequences within the pertinent substring.
Pattern p = Pattern.compile("\\b([GCATgcat]+)\\b");
Matcher m = p.matcher(pertinentSection);
List<String> sequences = new ArrayList<String>();
while (m.find()) {
sequences.add(m.group(1));
}
sequences.toString(); // => ["acagatgaag", "acagatgaag", ..., "acagatgaag"]
입력 문자열과 예상 출력을 제공 할 수 있습니까? – stema
그냥 해냈어 :) – user1044585
에서 읽는 파일에서 샘플을 추가하십시오. 라이프 폼을 구문 분석하는 정규식을 사용하지 마십시오 :) –