Using Find and Replace/Regular Expressions to Change Opening and Closing Tags
|Article #: GEN1016Z||Product: Flare||Version: All|
Below are the steps for using Regular Expressions in conjunction with Find and Replace to change opening and closing tags while maintaining the content inside of the tags.
When trying to replace an element with a entirely new element using a simple Find and Replace does not work effectively because we want to maintain the content in between tags as well as replace the closing tag. Regular expressions (also referred to as regex or regexp) are similar to wildcards in that they let you find matching strings of text. However, they are more powerful than wildcards. By using a regular expression we can change both the opening and closing tags while preserving the information between the tags.
In this example we want to change the source code below:
<p class="heading1">Hello MadWorld!</p>
- Navigate to the "Home" ribbon menu and select "Find and replace in Files"
- In the Find field insert:
- In the Replace with field insert "\1" with the desired opening and closing tags on either side:
- Under Find Options enable "Find in source code" and set Search Type to "Regular Expressions"
- Perform the find and replace and confirm that the tags have changed appropriately via the XML Editor
The "\1" used in the "Replace with" field in step 3 is called a backreference, this is used to match the text in the first logical grouping in the regular expression in the "Find" field in step 2. The first logical grouping, in this case, is everything within the outermost parentheses. This is what tells the find and replace to maintain the text within the xml tags.
For more information on regular expressions please visit the resources below.
September 30, 2016