This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Unfortunately i am not so good with regular expressions since i don't use them so often and i can't practice them as i would, but i would like to try to give you an answer because i think regular exepressions are a really expressive language.
i arrived to this one
If i am not wrong this expression recognises any character (zero or more times) followed by or sequence followed by any character (zero or more times)
But, as i told you, i am not so good with it and you surely find better answers
It says "any character any number of times" followed by a : or ) (because the  denote a character class, or a choice of characters) or a : or D, followed again by any character any number of times.
The regular expression needed is simple in this case:
- a :. Use the literal.
- a ) or D. Use either a character class or a | for this.
So you'd get ":[)D]" or ":(\\)|D)". Note that in the second example you need to escape the ). The first form is easier but allows extending only with two-character like :(. The regex would become ":[)D(]". The second form allows you to add any number of characters after the :. With additions :(, :'( and :wink: the regex would become ":(\\(|D|\\(|'\\(|wink:)". With a given set of smilies that can be automatically generated, using Pattern.quote (the : is taken inside the parentheses so you can also add smilies like ;) that don't start with :):
This will create a regex like this: Don't be put off by those \Q and \E; \Q means to treat everything until the next \E as literals instead of meta characters. See also the Javadoc of java.util.regex.Pattern.
Thanks for reply ! That's really a nice post to improve my knowledge about RE.
However, when I try to apply this regular expression to detect emoticon, I only can get the first emoticon in the sentence.
Is there any approach that I get get all the emoticons in the sentence ?