S
Soeren Meyer-Eppler
Hello,
I have a very frustrating problem getting Javas regexes to run. I have
no idea what I'm doing wrong, since even the most trivial expressions
don't find any matches - even when I've tested and verified them in
other regex enabled tools like UltraEdit or so.
The simplest test I could think of is the following:
public static void main(String[] args)
{
Pattern pattern = Pattern.compile( ".*" );
Matcher matcher = pattern.matcher( "hello" );
System.out.println( matcher.group());
}
which gives me:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at java.util.regex.Matcher.group(Unknown Source)
at BinNavi.GraphNavigator.main(GraphNavigator.java:1688)
WTF?! I mean shouldn't .* match just about anything? Including the empty
string? Similarly, matching "hello" to "hello" doesn't work, "t" to
"t"... Am I using it wrong?
I'm running on Java Version 1.5.0 (Build 1.5.0_06-b05), jdk1.5.0, my
test environment is Eclipse.
I'd appreciate any hints, since I'm sure this is a stupid mistake on my
part.
regards,
Sören Meyer-Eppler
I have a very frustrating problem getting Javas regexes to run. I have
no idea what I'm doing wrong, since even the most trivial expressions
don't find any matches - even when I've tested and verified them in
other regex enabled tools like UltraEdit or so.
The simplest test I could think of is the following:
public static void main(String[] args)
{
Pattern pattern = Pattern.compile( ".*" );
Matcher matcher = pattern.matcher( "hello" );
System.out.println( matcher.group());
}
which gives me:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at java.util.regex.Matcher.group(Unknown Source)
at BinNavi.GraphNavigator.main(GraphNavigator.java:1688)
WTF?! I mean shouldn't .* match just about anything? Including the empty
string? Similarly, matching "hello" to "hello" doesn't work, "t" to
"t"... Am I using it wrong?
I'm running on Java Version 1.5.0 (Build 1.5.0_06-b05), jdk1.5.0, my
test environment is Eclipse.
I'd appreciate any hints, since I'm sure this is a stupid mistake on my
part.
regards,
Sören Meyer-Eppler