diff --git a/src/JRexFrame.java b/src/JRexFrame.java index 7b36c9f..e5eeba1 100644 --- a/src/JRexFrame.java +++ b/src/JRexFrame.java @@ -356,6 +356,7 @@ }// //GEN-END:initComponents private void match() { + txtOutput.setText(""); String regex = txtRegex.getText(); String text = txtInput.getText(); @@ -403,6 +404,13 @@ Matcher matcher = pattern.matcher(line); while (matcher.find()) { + // group() matches the entire line if there was a match. + // This if-statment is to suppress extra empty groups from being + // produced if the regex matches the entire line + if(matcher.group().length() != line.length()) { + continue; + } + numMatches++; int groupCount = matcher.groupCount(); @@ -429,7 +437,6 @@ } } - txtOutput.setText(""); txtOutput.append("Matched " + numMatches + " line(s) out of " + input.length + " line(s) of input."); @@ -497,7 +504,6 @@ private void csv() { Integer cols = (Integer) spnColumns.getValue(); - System.out.println(cols); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols - 1; i++) { @@ -506,13 +512,11 @@ sb.append("(.*)"); - txtRegex.setText(sb.toString()); } private void tsv() { Integer cols = (Integer) spnColumns.getValue(); - System.out.println(cols); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols - 1; i++) { @@ -521,7 +525,6 @@ sb.append("(.*)"); - txtRegex.setText(sb.toString()); }