Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Representing open parentheses using Regular Expression

807589Aug 16 2008 — edited Aug 17 2008
Hi all,
I am trying to create a regular expression that would separate the rest of the text from smileys.

For example if the input text is
"Hello:)World:(Hello"

Then I should get the output as an array of strings as
{"Hello","World","Hello"}.

I figured out a way to do this would be to create Pattern and then use the split method on it as follows:
String str[];
Pattern p=Pattern.compile(":)");
str=p.split("Hello:)World:(Hello")
However I am getting the following error:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 0

How do I represent the opening parenthesis in a regular expression?
Also can I represent a combination of smileys in the regular expression?

Please help.
Any inputs on this would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2008
Added on Aug 16 2008
9 comments
4,302 views