Java tutorial
//package com.java2s; import java.util.Vector; public class Main { private static Vector<String> getConditionsOperatorTokens(String relevant) { //TODO For now we are only dealing with one AND or OR, for simplicity //If one mixes both in the same relevant statement, then we take the first. Vector<String> list = new Vector<String>(); int pos = 0; do { pos = extractConditionsOperatorTokens(relevant, pos, list); } while (pos > 0); return list; } private static int extractConditionsOperatorTokens(String relevant, int startPos, Vector<String> list) { int pos, pos2, opSize = 5; pos = relevant.toUpperCase().indexOf(" AND ", startPos); if (pos < 0) { pos = relevant.toUpperCase().indexOf(" OR ", startPos); opSize = 4; } //AND may be the last token when we have starting ORs hence skipping them. eg (relevant="/data/question10=7 OR /data/question6=4 OR /data/question8=1 AND /data/question1='daniel'") pos2 = relevant.toUpperCase().indexOf(" OR ", startPos); if (pos2 > 0 && pos2 < pos) { pos = pos2; opSize = 4; } if (pos < 0) { list.add(relevant.substring(startPos).trim()); opSize = 0; } else list.add(relevant.substring(startPos, pos).trim()); return pos + opSize; } }