Disclaimer: I'm still trying to learn elisp so I have not gotten yet to the RegExp section of the Elisp intro or Emacs manual.

I would like to know how to search and replace an HTML buffer that has elements with any number of attributes with my desired string (that to be filled by me). Basically, I need help building the RegExp that would match all the attributes that look like attr="[whatever string"

  • 1
    Maybe take a look at nxml-mode? See the Emacs manual, here. Hopefully, there will already be a way to search for XML attributes. (Regexps are not particularly well suited for this kind of search, I think.)
    – Drew
    May 28, 2020 at 19:16
  • I couldn't find a function that could do something similarly like I tried doing so with interactive commands. I marked several tags with mc/mark-all-dwim then web-mode-attribute-kill but that would be too slow and freeze up Emacs.
    – avocadoras
    May 29, 2020 at 3:31

1 Answer 1


Using web-mode you can traverse the dom tree element by element and then traversing element attributes killing/sparing each one manually without having to code anything, just learning the keybindings. Doing it automatically will require some coding. I guess you can do something similar with other related modes with more or less effort.

If you're looking for a quick and dirty regexp to match what resembles an attribute using C-M-% it could be something like [[:word:]]+="[^"]+"

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.