3

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?

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

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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