VS provides regular expressions in replacing string which can be a lifesaver. Here's a few examples of operations to be performed on many files:
Removing an xml attribute:
What the RE means: Find the string "<Survey " followed by a bunch of characters, followed by the string "cluster=" followed by a bunch of non-space characters. Replace with just the "<Survey " and the characters before "cluster".
regex: to delete the attribute "cluster" from the "Survey" element: Find What: \<Survey {.*} cluster=[^ ]* Replace With: \<Survey \1
Rename an attribute
In this case I want to rename the "Survey" element's 'id' attribute to 'registrarId', but not the other elements' 'id' attribute. The element name and the attribute to change must be on the same line for this to work. A tiny sliver of regular expression in the "Find and Replace" dialog did the trick: The "Find What" says find "<Survey " followed by any characters followed by " id=". The "\1" takes the value of all the characters skipped with the {.*}.
Find What: \<Survey {.*} id=
Replace with: \<Survey \1 registrarId=
No comments:
Post a Comment