How to get the string after last comma in java?

后端 未结 9 788
谎友^
谎友^ 2020-12-18 18:14

How do I get the content after the last comma in a string using a regular expression?

Example:

abcd,fg;ijkl, cas

The output should

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 18:21

    Only one space:

    String[] aux = theInputString.split(",\\s");
    string result = aux[aux.length-1];
    

    0 to n spaces:

    String[] aux = theInputString.split(",\\s*");
    string result = aux[aux.length-1];
    

提交回复
热议问题