In the Search | Replace menu of Toad, how does the 'Replace with template' work?
Note: Please go to Help | Contents | Search with key word 'Regular Expression' for info on what a regular expression is.
In this solution, we will use the example regular expression '(se.*t)(.*?)(emp)' on the query 'SELECT * FROM EMP.'
When you type '(se.*t)(.*?)(emp)' in the 'Text to find' field it means you are trying to find 'SELECT * FROM EMP.' When the 'Replace with template' check box is checked, the value in the 'Replace width' field is not a string anymore, but rather it back references the substrings in the 'Text to find' field.
Each '( )' in 'Text to find' is a substring. If you type '\1\2\3' into the 'Replace width' field, it means you are setting a reference point to the substrings above.
\1 correspond to (se.*t)
\2 correspond to (.*?)
\3 correspond to (emp)
If you type '\1\2dept,\3' it means you want to replace what '\2' correspond to with 'dept,.'
So 'SELECT * FROM EMP' becomes 'SELECT * FROM dept, EMP.'
When the 'Replace with Template' box is NOT checked then the values in the 'Replace width' field DO NOT back reference and it is treated as a string to insert:
So 'SELECT * FROM EMP' becomes '\1\2dept,\3.'
There is a defect with the Search | Replace window. When you check the 'Regular expressions' box it should enable the 'Replace with template' box, but it does not. The workaround is to search for something not there (e.g. '0'). It will come back saying it did not find '0.' Then, go back to Search | Replace (CTRL-R) and you'll see them both enabled.
© ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center