0

I need to put a new attribute inside a particular tag that doesn't have it already.

I've found something similar to my needs that helps locate those tags, but I am very new to regex and I am having trouble with it.

Here, master @RidgeRunner nicely explains how to find it. Now, I found hundreds of ocurrences along the code. It will be exhausting to manually input the missing attribute in all those tags.

Is there a chance that eclipse replace tool may help me? How?

Thanks

Community
  • 1
  • 1
djejaquino
  • 172
  • 1
  • 7

1 Answers1

1

If you put a \1 in the replace field, it will be replaced with whatever the first bracket in the regex matches. For example, if you use this regex in the find field

(<input )

and this text in the replace field

\1name="abc"

, then you will replace all <input instances with <input name="abc". Likewise, using \2 will copy the second bracket, etc.

This should be enough to add attributes, but be careful of elements that already have that attribute. If this is the case then you can search the replaced text again for elements that have this attribute defined twice, like this:

(<input )name="abc"(.*? name=.*?>)

and replace with

\1\2

This will remove the new attribute you added from those elements which already had the attribute defined.

Marc Tanti
  • 71
  • 2