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
Example (Remove the last b character)
System.out.println("1abchhhabcjjjabc".replaceFirst("(^.+)b(.+$)", "$1$2"));
Outputs (Notice the underlined portion of string)
1abchhhabcjjjac
Comments
Post a Comment