What's wrong with Matcher.matches()

Look at the following code:

String regex = "(\\x2A*\\p{Space}*)*";

Pattern strangePatter = Pattern.compile(regex);

Matcher m = strangePatter.matcher("***********************************" +

"******************************************** * ");

if (m.matches())

System.out.println("Matched");

else

System.out.println("No.");

This code stucks at "if (m.matches())" and m.matches() never returns. What could be the problem?

[487 byte] By [dr_wack] at [2007-9-30 12:18:49]
# 1
Surprising ! This code that you pasted seems to work fine for me. I ran it using an IDE as well as from the command line and it works just fine.
john.m at 2007-7-4 15:27:27 > top of Java-index,Administration Tools,Sun Connection...
# 2
It could be that the matcher is using a very slow search path. What happens if you search a much shorter string of asterisks?
Alistair_Wall at 2007-7-4 15:27:27 > top of Java-index,Administration Tools,Sun Connection...
# 3

I get this problem too. Windows JVM 1.4.2_05 and prior.

In my case I have a 32000 char string with the words "toes toes toes"... and so on (don't ask why).

I am trying to locate any email addresses in this text using:

static Pattern bodyAddrPattern = Pattern . compile ("(\\w[-a-zA-Z0-9' ]*[^ ]) *\\[(?:SMTP|mailto):([^]]+)\\]");

This does not return. It does not consume any additional memory. It just uses 99% of cpu, for hours on end!

This pattern is used successfully on thousands of other strings. And if I truncate the string to 2000 characters, then it works.

MBeedell at 2007-7-4 15:27:27 > top of Java-index,Administration Tools,Sun Connection...
# 4

> I get this problem too. Windows JVM 1.4.2_05 and

> prior.

>

> In my case I have a 32000 char string with the words

> "toes toes toes"... and so on (don't ask why).

>

> I am trying to locate any email addresses in this text

> using:

>

> static Pattern bodyAddrPattern = Pattern . compile

> ("(\\w[-a-zA-Z0-9' ]*[^ ])

> *\\[(?:SMTP|mailto):([^]]+)\\]");

>

>

> This does not return. It does not consume any

> additional memory. It just uses 99% of cpu, for hours

> on end!

>

> This pattern is used successfully on thousands of

> other strings. And if I truncate the string to 2000

> characters, then it works.

I suspect that you do a test timing for strings in a range like (10, 20,...100, 200,...900, 1000, 2000,....9000,... ) you will see that the time for each increases exponentially.

jschell at 2007-7-4 15:27:27 > top of Java-index,Administration Tools,Sun Connection...