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)


   1abchhhabcjjjac

Comments

Popular posts from this blog

Hosting Apache Tapestry5.1 on GAE (Google App Engine)

Apache Tapestry PageActivationContext tutorial

MySQL workbench not working on Windows 7