As mrainey56 has written ^s is the code for selected text. But you need this only for a search (+ replace) within a macro. If you have a selection and execute the replace command, the selected text is automatically inserted in the "Find What" field. You only have to expand the string now with the code mrainey56 as written for Unix style regular expression or with following code for UltraEdit style:
Find What:
%*search string
*^p
If you run this regular expression replace, you can delete all lines containing this string. However, there is one problem.
The selected string, which is automatically used as search string during command call, should not have any character, which is interpreted as regular expression character. For example characters like
*[] should not be inside the selected string. If the selected string contains such characters, you have to insert the escape character ^ for UltraEdit style or \ for Unix style before every special regular expression character.
^s cannot be used in a regular expression search in Unix style in the search string. This is mentioned in the help of UltraEdit at bottom of the topic about regular expressions. With UltraEdit style ^s can be used inside a regular expression search string, but you must know, that the selected string will be interpreted as regular expression and not as normal text.
For better understanding this, I post here the important part of an email, which I have written on 2005-09-16 (3 days ago) to IDM and which was confirmed by IDM.
-----------------------
I noticed, that ^c and ^s are simply not working in a regular expression search with Unix style. This is already mentioned in the help of UltraEdit at bottom of the regular expression help page. So the difference is that UltraEdit supports ^c and ^s in an UltraEdit style regular expression find whereelse they are not supported in an Unix regular expression find.
As a result of this issue, the difference about interpretation of ^s and ^c and other ^? codes should be better explained in the help. What can be used in UltraEdit style regular expression and how is it interpreted.
You can look at my example and what was the problem for me and why I first wanted to use %^c$ in an UltraEdit style regular expression.
The example file is Testfile.txt which has following content:
Code: Select all
with time
without + with time
with 3 octet time
with 7 octet time
with 3 + 7 octet time
with time
without + with time
with 7 octet time
with 3 + 7 octet time
not used
;
Strings EN;Strings DE
with time;mit Zeit
without + with time;ohne + mit Zeit
with 3 octet time;mit 3 Oktett Zeit
with 7 octet time;mit 7 Oktett Zeit
with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
not available;nicht verfügbar
At top of the file it contains some strings which were collected before from an other file (content is similar to a windows resource file). Some strings are duplicate and some strings have only an identical part at end of the string. Each string is on a separate line. After these strings, there is a line, which only have a ; at column 1. This is the marker, where the collected strings where inserted before into the file. The Testfile.txt is a CSV file which has a header row followed by rows with already translated english and german strings separated by a ;.
The macro now has to search for each string at top of the file for an 100% match in the CSV area. If a string can be found in the CSV area, the string at top of the file and all it's duplicates in the upper area can be deleted, because this string was already translated.
Two lines demonstrates the main problem, why I wanted to use ^s inside a regular expression without interpretation of the selected string as regular expression:
with time
without + with time
String "with time" is identical to a part of string "without + with time". The macro has to make sure not to remove strings, which are part of other strings. The second problem is the + character, which is a regular expression character.
Macro which I first thought should do the job with regular expressions in UltraEdit style.
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
Top
Loop
IfCharIs ";"
ExitLoop
EndIf
StartSelect
Key END
Copy
EndSelect
Find RegExp "%^c;"
IfNotFound
Key HOME
"!NEW="
Key END
";"
Key HOME
Key DOWN ARROW
Else
Top
Find RegExp "%^c$"
Key HOME
Find RegExp "%^c^p"
Replace All ""
EndIf
EndLoop
DeleteLine
ClearClipboard
Clipboard 0
Top
The result of this macro at Testfile.txt is:
Code: Select all
!NEW=without + with time; <- WRONG RESULT !!!
!NEW=with 3 + 7 octet time; <- WRONG RESULT !!!
!NEW=without + with time; <- WRONG RESULT !!!
!NEW=with 3 + 7 octet time; <- WRONG RESULT !!!
!NEW=not used;
Strings EN;Strings DE
with time;mit Zeit
without + with time;ohne + mit Zeit
with 3 octet time;mit 3 Oktett Zeit
with 7 octet time;mit 7 Oktett Zeit
with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
not available;nicht verfügbar
The wrong results are caused by the interpretation of the + character as regular expression character.
Here is the solution I now use. It has the advantage, that also translated strings which where not present anymore in the "resource" file are marked in the CSV file after macro execution.
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
Top
Find RegExp "%;"
Key HOME
SelectToTop
Find RegExp "%^(*^)$"
Replace All SelectText ">>^1<<"
EndSelect
Top
Find RegExp "%;"
Key DOWN ARROW
Key DOWN ARROW
SelectToBottom
Find RegExp "%^(*^)$"
Replace All "!DEL=^1"
EndSelect
Top
Loop
IfCharIs ";"
ExitLoop
EndIf
Key RIGHT ARROW
Key RIGHT ARROW
StartSelect
Key END
Key LEFT ARROW
Key LEFT ARROW
Copy
EndSelect
Find "!DEL=^c;"
IfNotFound
Key HOME
Key DEL
Key DEL
"!NEW="
Key END
Key BACKSPACE
Key BACKSPACE
";"
Key HOME
Key DOWN ARROW
Else
Key HOME
Find "!DEL="
Delete
Top
Find ">>^c<<"
Key HOME
EndIf
Find ">>^c<<^p"
Replace All ""
EndLoop
DeleteLine
ClearClipboard
Clipboard 0
Top
The result of this macro is what I want:
Code: Select all
!NEW=not used;
Strings EN;Strings DE
with time;mit Zeit
without + with time;ohne + mit Zeit
with 3 octet time;mit 3 Oktett Zeit
with 7 octet time;mit 7 Oktett Zeit
with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
!DEL=not available;nicht verfügbar