Hi,

I initially sent this message before I was properly subscribed, so I
apologize if it shows up again....

I've been having some (apparently) odd behavior with regular
expressions. Can anyone please tell me if the following program should
work as I am seeing?

---
import org.apache.xerces.impl.xpath.regex.RegularExpression;;

public class ReTest {
 public static void main(String[] args) {
   String s = "Another test";
   String p1 = "foo";
   String p2 = "foo.*test";

   RegularExpression re = new RegularExpression(p1);
   print(s, p1, re.matches(s));
   re.setPattern(p2);
   print(s, p2, re.matches(s));
   re = new RegularExpression(p2);
   print(s, p2, re.matches(s));
 }

 static void print(String str, String pattern, boolean match) {
   System.out.print("Pattern '" + pattern);
   if (match) System.out.print("' matches '");
   else System.out.print("' does not match '");
   System.out.println(str + "'");
 }
}
---

The output I expect to see is:
 Pattern 'foo' does not match 'Another test'
 Pattern 'foo.*test' does not match 'Another test'
 Pattern 'foo.*test' does not match 'Another test'

The output I actually see is:
 Pattern 'foo' does not match 'Another test'
 Pattern 'foo.*test' matches 'Another test'
 Pattern 'foo.*test' does not match 'Another test'

In other words, setPattern() is not working the way I expect it to. Is
this right?

Thanks in advance,
Paul Gearon

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to