\\b([GCATgcat]+)\\b
単語の境界で囲まれたGCAT文字シーケンス(大文字または小文字)に一致するこのパターン ""を試してください(したがって、単語 "catalog"などの他の文字列に埋め込まれている文字とは一致しません)。サンプルファイルでこの正規表現を繰り返しスキャンすると、各シーケンスが抽出されます。
サンプルファイルの実際の例を次に示します。
// 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"]