Simple Regex Not Working

Hi,

Can somebody tell me why the following regex matching does not work:

Pattern.matches("(hi)*","hithere");

[178 byte] By [aria_kokoschkaa] at [2007-11-27 11:28:42]
# 1

> Hi,

>

> Can somebody tell me why the following regex matching

> does not work:

>

> > Pattern.matches("(hi)*", "hithere");

>

Your regex would only match

"hi" or "hihi" or "hihihi" etc.

I suspect you need as regex "hi.*" .

sabre150a at 2007-7-29 16:23:39 > top of Java-index,Java Essentials,Java Programming...
# 2

Argh! Thank you for pointing that out. Actually this should work: .*(hi).* as I am interested in finding that particular string anywhere in the input.

aria_kokoschkaa at 2007-7-29 16:23:39 > top of Java-index,Java Essentials,Java Programming...
# 3

then try matcher.find() rather than .matches().

This way the regex can remain "hi" alone.

TuringPesta at 2007-7-29 16:23:39 > top of Java-index,Java Essentials,Java Programming...