[Solved] How to split String from one word to another?


This code should work.

String info = "You have 2$ on your public transport card and one active ticket which expires on 2017-08-09 23.59";
    Pattern pattern = Pattern.compile("(\\d\\$).*and\\s(.*)");
    Matcher m = pattern.matcher(info);
    while (m.find()) {
        System.out.println("First Group: " + m.group(1) + " \nSecond Group: " + m.group(2));
    }

Just like Andreas said before, you should use Pattern and regular expressions to find the groups in your String info and then you can safe them in variables, for now i just printed them.

solved How to split String from one word to another?