M
MARTIN Herve
Hi,
I have a problem with the use of an object Pattern recovered from a
serialization/unserialization process.
My pattern is "([A-Z]):[A-Z])"
p = Pattern.compile ("([A-Z]):[A-Z])");
It defines 2 groups between ( ).
With the input string "B::C", the matcher normally identifies 2 groups which
values are: "B" and "C"
m = p.matcher ("B::C");
If the pattern p is serialized /unserialized before being used to create the
matcher,
then the matcher identifies only 1 group, which value is "C".
Can someone explain why ???
Thanks,
Hervé.
Java version is 1.4.1_02; it runs on a Sun machine.
Here is a full test program:
import execution.TRegExpr;
import java.io.*;
import java.util.regex.*;
class a
{
static void find (Matcher m) {
if (m.find ()) {
int n = m.groupCount ();
for (int k=0; k<=n; k++)
System.out.println (""+k+": "+m.group (k));
}
}
public static void main (String[] args) {
String regexpr = "([A-Z]):[A-Z])";
Pattern p0 = Pattern.compile (regexpr);
Pattern p1 = null;
String fileName = "pattern.bytes";
try {
ObjectOutputStream os = new ObjectOutputStream (new
FileOutputStream (fileName));
os.writeObject (p0);
os.close ();
ObjectInputStream is = new ObjectInputStream (new
FileInputStream (fileName));
p1 = (Pattern)is.readObject ();
is.close ();
}
catch (Exception e) {
System.out.println ("ERROR: "+e.getMessage ());
}
String input = "B::C";
find (p1.matcher (input));
find (p0.matcher (input));
}
}
I have a problem with the use of an object Pattern recovered from a
serialization/unserialization process.
My pattern is "([A-Z]):[A-Z])"
p = Pattern.compile ("([A-Z]):[A-Z])");
It defines 2 groups between ( ).
With the input string "B::C", the matcher normally identifies 2 groups which
values are: "B" and "C"
m = p.matcher ("B::C");
If the pattern p is serialized /unserialized before being used to create the
matcher,
then the matcher identifies only 1 group, which value is "C".
Can someone explain why ???
Thanks,
Hervé.
Java version is 1.4.1_02; it runs on a Sun machine.
Here is a full test program:
import execution.TRegExpr;
import java.io.*;
import java.util.regex.*;
class a
{
static void find (Matcher m) {
if (m.find ()) {
int n = m.groupCount ();
for (int k=0; k<=n; k++)
System.out.println (""+k+": "+m.group (k));
}
}
public static void main (String[] args) {
String regexpr = "([A-Z]):[A-Z])";
Pattern p0 = Pattern.compile (regexpr);
Pattern p1 = null;
String fileName = "pattern.bytes";
try {
ObjectOutputStream os = new ObjectOutputStream (new
FileOutputStream (fileName));
os.writeObject (p0);
os.close ();
ObjectInputStream is = new ObjectInputStream (new
FileInputStream (fileName));
p1 = (Pattern)is.readObject ();
is.close ();
}
catch (Exception e) {
System.out.println ("ERROR: "+e.getMessage ());
}
String input = "B::C";
find (p1.matcher (input));
find (p0.matcher (input));
}
}