I work for a company where I develop an Angular application. A component library internal to the company I work for has released some changes to the HTML markup format. For example, in the the previous version this was valid:
<component-name directive some-other-attribute="" *ngIf=" etc></component-name>
However, the maintainers of this library have released an update that changes the structure to this:
<directive><component-name some-other-attribute *ngIf="" etc></component-name></directive>
Essentially, what was originally the directive has been made a component in it's own right.
The application I work on has 100s of these occurrences, and going through them all and doing this is extremely tedious work and will take many hours. Is there a regular expression where I can match the first part of the original string (<component-name directive
), ignore every thing else, until it reaches the closing tags, and replace then the starting and closing tags with with <directive><component-name [everything else]></component-name></directive>
. It has to be done this way as there are some instances where <component-name>
is used without the directive
and I do not want those instances to have </directive>
closing tags.
I use WebStorm as my IDE, so can use any of the refactoring/find and replace functions in there, although am open to any Terminal tool which will do the job.
While I know Regex is not supposed to be used for anything to do with HTML, I'm unsure what else I would use (obviously, suggestions/solutions welcome). I have already tried some Regular Expressions (I'm pretty rubbish at these), such as:
<component-name directive [^.*(?=>)]<\/component-name>
Here I am trying to match the first part, and ignore everything up until the closing tags. However, I'm unsure how I would substitute the new text for the matches (although am aware I could use WebStorm find-and-replace with regex to maybe do this). However, this didn't quite work.
To summarise: I need <component-name directive [other attributes ignored]></component-name>
to be replaced with <directive><component-name [other attributes ignored]></component-name></directive>
.
EDIT: while I realise this isn't really programming, I'm not sure where-else I would post it. I've added the WebStorm tag and removed the Angular one, but I'm open to using any other tool to get the job done.