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 getConditionOfExpression(String expression) { // pattern for conditions Pattern conditionPattern = Pattern .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])(/[\\w\\W]+)?$"); Matcher conditionMatcher = conditionPattern.matcher(expression); if (conditionMatcher.find() && (conditionMatcher.group().length() == expression.length())) { StringTokenizer st = new StringTokenizer(expression, "]"); String condition = st.nextToken(); condition = condition.substring(condition.indexOf("[") + 1); return condition; } return null; } }