Home > Software design >  last two occurance of semicolon(;) in given String using Java
last two occurance of semicolon(;) in given String using Java

Time:11-11

How do I get the after last two semicolon's occurrences of a string ?

Example:

Mobiles;Students;Test;Yes;1234

The output should be Yes;1234

CodePudding user response:

Using a regex replacement, we can try:

String input = "Mobiles;Students;Test;Yes;1234";
String output = input.replaceAll("^.*;([^;] ;[^;] )$", "$1");
System.out.println(output);  // Yes;1234
  • Related