> Pattern p=new Pattern("dialer%instance%.+%name");
> Matcher matcher=p.matcher("dialer%instance%name");
> System.out.print(matcher.matches()) ==> This prints 'true'!
>
> How come, it matches?
Hard to say, since the code you tested isn't the code you posted.
For example, there is no public constructor for Pattern. After making
that correction, I get "false" as expected.
Post real, compilable code if you want a useful answer.
> I expected e.g) "dialer%instance%1%name" or "dialer%instance%1%name"
> would only match.
Did you mean to post two identical examples here?
> But, why "dialer%instance%name" also matches the pattern specified?
It doesn't.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Shouldn't you construct patterns like this:
Pattern p = Pattern.compile("dialer%instance%.+%name");
> Pattern p=new Pattern("dialer%instance%.+%name");
> Matcher matcher=p.matcher("dialer%instance%name");
> System.out.print(matcher.matches())
> Hi,
>
> Pattern p=new Pattern("dialer%instance%.+%name");
> Matcher matcher=p.matcher("dialer%instance%name");
> System.out.print(matcher.matches()) ==> This prints 'true'!
No.
> How come, it matches? I expected e.g) "dialer%instance%1%name"
> or "dialer%instance%1%name" would only match. But, why
> "dialer%instance%name" also matches the pattern specified?
You're confused. Your code doesn't even compile.
robert
Oops, some errta correction.
Pattern p=new Pattern.compile("dialer%instance%.+%name");
Matcher matcher=p.matcher("dialer%instance%name");
System.out.print(matcher.matches()) ==> This prints 'true'!
How come, it matches? I expected e.g) "dialer%instance%1%name"
or "dialer%instance%2%name" would only match. But, why
"dialer%instance%name" also matches the pattern specified?
> Hi,
>
[quoted text clipped - 5 lines]
> or "dialer%instance%1%name" would only match. But, why
> "dialer%instance%name" also matches the pattern specified?
Robert Klemme - 14 Jun 2006 18:00 GMT
> Oops, some errta correction.
>
> Pattern p=new Pattern.compile("dialer%instance%.+%name");
> Matcher matcher=p.matcher("dialer%instance%name");
> System.out.print(matcher.matches()) ==> This prints 'true'!
You're still confused. Go away.
robert
Hendrik Maryns - 14 Jun 2006 18:21 GMT
itsolution@gmail.com schreef:
> Oops, some errta correction.
>
[quoted text clipped - 5 lines]
> or "dialer%instance%2%name" would only match. But, why
> "dialer%instance%name" also matches the pattern specified?
You code still does not compile. Remove ‘new’, and try it out first if
you post again in the future.
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Patricia Shanahan - 14 Jun 2006 19:00 GMT
> Oops, some errta correction.
>
[quoted text clipped - 5 lines]
> or "dialer%instance%2%name" would only match. But, why
> "dialer%instance%name" also matches the pattern specified?
Rather than posting errata, it seems to be time for a Short,
Self-Contained, Compilable Example (SSCCE). I tried to construct one
from the snippet you posted. I had edit out "new " to get it to compile,
so I know what you posted is not what you are running. This program
prints "false", so some difference from what you are running is
significant.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PatternTest {
public static void main(String[] args) {
Pattern p=Pattern.compile("dialer%instance%.+%name");
Matcher matcher=p.matcher("dialer%instance%name");
System.out.print(matcher.matches());
}
}
Your best bet for getting help is to edit this example to make it match
what you are doing, and post the new version. Make sure you copy-paste,
with no retyping, when you post it, so that the program in the message
is EXACTLY the program you are running.
Keep the form of a very short but complete program. Anyone who wants to
help you should be able to copy-paste the program from your message into
their favorite Java editor and reproduce your problem without having to
add, delete, or change a single byte.
Patricia