Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> public static void main(String[] args) { Scanner s = new Scanner("Shortest path(2)::RV3280-RV0973C-RV2888C" + "\nShortest path(1)::RV3280-RV2502C" + "\nShortest path(2)::RV3280-RV2501C-RV1263" + "\nShortest path(2)::RV2363-Rv3285-RV3280"); while (s.hasNextLine()) { s.findInLine("Shortest path\\((\\d+)\\)::(\\w+).*-(\\w+)"); // at each line, look for this pattern MatchResult result = s.match(); // results from for (int i = 1; i &lt;= result.groupCount(); i++) { System.out.println(result.group(i)); } s.nextLine(); // line no. 29 } s.close(); } } run: 2 RV3280 RV2888C 1 RV3280 RV2502C 2 RV3280 RV1263 2 RV2363 RV3280 BUILD SUCCESSFUL (total time: 0 seconds) </code></pre> <p>This works well for me, maybe you have some weird characters or empty lines in your file?</p> <p>2 empty lines at the end give me that: Exception in thread "main" java.lang.IllegalStateException: No match result available</p> <p>If your input file is that strictly formatted, you can do something like that, which is way easier because you can get rid of that nasty regex ;)</p> <pre><code> String[] lines = new String[]{"Shortest path(2)::RV3280-RV0973C-RV2888C", "Shortest path(1)::RV3280-RV2502C", "Shortest path(2)::RV3280-RV2501C-RV1263", "Shortest path(2)::RV2363-Rv3285-RV3280", "\n", "\n"}; final int positionOfIndex = 14; final int startPositionOfProteins = 18; for (String line : lines) { if (!line.trim().isEmpty()) { System.out.print(line.charAt(positionOfIndex) + ": "); String[] proteins = line.substring(startPositionOfProteins).split("-"); System.out.println(proteins[0] + " " + proteins[proteins.size() -1]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload