Java tutorial
//package com.java2s; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String getEventOfExpression(String expression) { // pattern for events Pattern eventPattern = Pattern.compile("^[\\w\\W&&[^/\\[\\]]]+(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)?$"); Matcher eventMatcher = eventPattern.matcher(expression); if (eventMatcher.find() && (eventMatcher.group().length() == expression.length())) { StringTokenizer st = new StringTokenizer(expression, "[]/"); return st.nextToken(); } return null; } }