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)

Testing SOAP services using pingdom

Apache Tapestry PageActivationContext tutorial