What is regex for replacing &f afrer same

I have string like this:

Hello &f are &f you &f here?

And I want to replace only last &f with "" (by last I mean third one, which is near "here". I tried something like this:

"Hello &f are &f you &f here?".replaceAll(".&f", "")

But it doesn't work, so could someone help me?


Can also be done with StringBuilder.reverse()

String str1 = "Hello &f are &f you &f here ?";
String temp = new StringBuilder(str1).reverse().toString().replaceFirst("f&", "");
String rslt = new StringBuilder(temp).reverse().toString();


  1. Reverse the String using StringBuffer
  2. Replace first f& with the help of String.replaceFirst()
  3. Then again reverse that String.


Hello &f are &f you  here ?

    String s = "Hello &f are &f you &f here?";
    s = s.substring(0,s.lastIndexOf("&f")) + s.substring(s.lastIndexOf("&f")+3);
    System.out.println("s = " + s); // prints: s = Hello &f are &f you here?

Use this:


And replace with the backreference $1. (Or is it \1 in Java?)


Need Your Help

IE designMode Showing display:none Divs

javascript jquery internet-explorer tinymce designmode

I've done a lot of research on this,but I'm unable to solve this problem. I've got a Div with several Divs within it that I want to hide before switching on a TinyMCE instance.

CSS selector to match elements by attribute's name start

css css-selectors

Is there any CSS selector to match these elements? (I need it for adblocker config, looked at W3C selectors document - no hints found there. Generic solution needed because part after data-d- gets