public class JRegexTest
{
public static void main(String[] args) throws IOException
{
String regex = args[0];
Pattern pattern;
if (args.length > 1) {pattern = new Pattern(args[0],args[1]);}
else pattern = new Pattern(args[0]);
String text = new BufferedReader(new InputStreamReader(System.in)).readLine();
Matcher matcher = pattern.matcher(text);
System.out.println("Searching \""+matcher.target()+"\" for pattern \""+matcher.pattern().toString()+"\"...");
while (matcher.find(Matcher.ACCEPT_INCOMPLETE))
{
System.out.println("found match \""+matcher.group(0)+"\" of length "+matcher.length()+" between indices "+matcher.start()+" and "+matcher.end());
System.out.println("prefix|match|suffix = \""+matcher.prefix()+"|"+matcher.group(0)+"|"+matcher.suffix()+"\"");
}
}
}
----------------
and this command:
----------------
echo cat | java JRegexTest a.a"
----------------
I get the output:
----------------
found match "null" of length -1 between indices 0 and -1
----------------
followed by a StringIndexOutOfBoundsException
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I know that I use it as a parameter to find() but how do I get useful information out of the MatchResult methods? I tried it and got these results.
With this test class:
JRegexTest.java
----------------
package net.BeechHaven.Eli.test;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import jregex.Pattern;
import jregex.Matcher;
public class JRegexTest
{
public static void main(String[] args) throws IOException
{
String regex = args[0];
Pattern pattern;
if (args.length > 1) {pattern = new Pattern(args[0],args[1]);}
else pattern = new Pattern(args[0]);
String text = new BufferedReader(new InputStreamReader(System.in)).readLine();
Matcher matcher = pattern.matcher(text);
System.out.println("Searching \""+matcher.target()+"\" for pattern \""+matcher.pattern().toString()+"\"...");
while (matcher.find(Matcher.ACCEPT_INCOMPLETE))
{
System.out.println("found match \""+matcher.group(0)+"\" of length "+matcher.length()+" between indices "+matcher.start()+" and "+matcher.end());
System.out.println("prefix|match|suffix = \""+matcher.prefix()+"|"+matcher.group(0)+"|"+matcher.suffix()+"\"");
}
}
}
----------------
and this command:
----------------
echo cat | java JRegexTest a.a"
----------------
I get the output:
----------------
found match "null" of length -1 between indices 0 and -1
----------------
followed by a StringIndexOutOfBoundsException