Search code examples
htmlvue.jswebstormstructural-search

Replace HTML tag based on attribute value


I need to replace vanilla <a> tag by different tag (<router-link>) in whole project. The main problem is to do it with some conditions based on href value (e.g. it should ignore href with "#").

I wrote regex, but it was really massive and sometimes cause issues.


Solution

  • After some research I found that webstorm(and other) has "Structural Replace" feature which help with it. I create follow structural replace: enter image description here enter image description here Main poins:

    • $before$ and $after$ have count filter = [0, infinity]
    • $before$ ignore 'href'
    • $href$ has script which filter some values