Sublime Forum

Selectively changing tag attributes with regex or xpath

#1

Hello,

I have an HTML snippet containing multiple IMG tags. The first tag needs to get a class “firstImage” while all other img tags need to get class “bodyImage”.

I was able to easily make a regex that puts bodyImage as the attribute for all tags. That’s fine and saves me time, but it’s a partial solution (and a bit of a hack as I’m using regex to edit XML, never a good idea).

Ideally I would like to use xpath expressions to do this. Is there any way to do it in Sublime?

0 Likes