samedi 19 novembre 2016

java pattern regex accepting string or string followed by digit

Having trouble with this piece of code. It is suppose to accept the following inputs, U,R,E,X or +,-,*,/ followed by a space and digit

   public static void main(String[] args) {
   Scanner input = new Scanner( System.in );//scanner
   System.out.println("COMP10152 - Lab#5 - Calculator using Queues and Stacks ... by _______________ \n");
   System.out.println("Enter tokens. Legal tokens are integers, +, -, *, /, U[ndo], R[edo], E[valuate] and [e]X[it] ");
   while (!input.hasNext("[UREXurex]?[+-*/]{1}[0-9][1]")) {
System.out.println("Invalid Entry - Please enter operation (operator(+,-,*,/) value) or U,R,E,X");
input.next();
   }

Aucun commentaire:

Enregistrer un commentaire