I want to add extra expressions to some JS code, but taking care of the correct element ID (in the example below, the ID is scatter).

document.getElementById("scatter").height="400"; -->
document.getElementById("scatter").height="400"; document.getElementById("scatter").style="visibility: visible"; 

My attempt so far has been:

M-x replace-regexp RET 
Id("\(\w+\)").height="400"; RET 
Id("\0").height="400"; document.getElementById("\0").style="visibility: visible";

Where \(\w+\) grabs the element ID and \0 references it on the replacement string. Unfortunately replace-regexp is complaining that I'm using \incorrectly.

Could anyone point out what I'm doing wrong?

  • 1
    Try \1 instead of \0. – Drew Jul 2 '16 at 14:23
  • That solved it, thx. – dangom Jul 2 '16 at 14:25

In a regexp replacement pattern, \N matches a subgroup, and \1, not \0 matches the first subgroup.

I just filed Emacs bug #23884 to help clarify the doc about this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.