Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final Map<Pattern, Integer> emoticons = new HashMap<Pattern, Integer>(); public static int getRedId(String string) { for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(string); while (matcher.find()) { return entry.getValue(); } } return -1; } }