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 be cas
Note: There is a space between last comma and 'c' character which also needs to be removed.
Also the pattern contains only one space after last comma.
Using regular expressions:
Outputs:
Or you can use simple
Stringmethods:System.out.println(s.substring(s.lastIndexOf(",") + 1).trim());System.out.println(s.substring(s.lastIndexOf(", ") + 2));