Posts

Showing posts from February, 2014

Replace\remove last occurrence of a string using regular expressions

Try this regex (^.+)b(.+$) Example (Remove the last b  character)     System.out.println("1abchhhabcjjjabc".replaceFirst("(^.+)b(.+$)", "$1$2")); Outputs (Notice the underlined portion of string)     1abchhhabcjjj ac