Regular Expressions in Java

I need a regular expression that should recognize the following text or anyother with a same format.

e.g. [C A_Thinking] my name is Suleman. [Hello] Who are you by the way. [Bye].

In the above text example i want that the pattern should match first *my name is Suleman* and in the second iteration *Who are you by the way.*. This could be one example, matched text strings could be any english sentence. The pattern should skip *[C A_Thinking]* and *[Bye].*. Remember there is a space in between *[C A_Thinking]* (C and A_Thinking).

I'm using Pattern and Matcher classes from java's R.E package.

Looking forward to ur reply.

Regards Suleman.

[680 byte] By [buttsp] at [2007-9-30 19:04:10]
# 1

I'm not an expert in regex but i think this would work.

Pattern p = Pattern.compile("\[.*\](.*)\[.*\](.*)\[.*\]");

then

Matcher match = p.matcher("[C A_Thinking] my name is Suleman. [Hello] Who are you by the way. [Bye]");

match.matches();

String myname = matcher.group();

String whoru = matcher.group();

Hope this help, although it's untested.

sat1196 at 2007-7-6 23:13:45 > top of Java-index,Desktop,Developing for the Desktop...
# 2
Regex will do the trick for you. It is hard to understand and can make your brain hurt, but it is an extremely powerful class, new to the Sun classes. It is worth the time and effort to understand it.
AT_losthiker at 2007-7-6 23:13:45 > top of Java-index,Desktop,Developing for the Desktop...