You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Paul Gearon <ge...@ieee.org> on 2009/02/19 22:13:24 UTC
Regex question
Hi,
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-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Fwd: Regex question
Posted by Paul Gearon <ge...@ieee.org>.
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-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Regex question
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Paul,
setPattern() is an undocumented method of an implementation class. From a
user perspective I wouldn't "expect" it to do anything. It's not part of
the API and no guarantee that it will even be there from release to release
(though probably unlikely that we'd remove it). The only place Xerces ever
calls setPattern() is within the constructor of RegularExpression. That's
probably the only place where it was intended that it would be called.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
gearon@ieee.org wrote on 02/19/2009 04:13:24 PM:
> Hi,
>
> 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-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org