Search and Replace Tool (SRT)
The String Parser is used to search and replace substrings.
| | |
|
TREE/Species/Search:PARSE FIELD
TREE/Properties/NDS
| | |
|
Basic search replace command:
searches all occurrences of 'search' and replace each by 'replace'
Multiple search/replace commands can be separated by the character ':':
'search1=replace1:search2=replace2: ... :searchn=replacen'
first searches all 'search1' and replaces each with 'replace1', then searches all 'search2' and replaces each with 'replace2', and so on.
The order of the SRT commands will affect the result. Examples:
-
'i=o:a=i' replaces all 'i' by 'o' and all 'a' by 'i'.
-
'a=i:i=o' effectively replaces all 'a' and all 'i' by 'o'. Each 'a' first gets replaced by 'i', which later gets replaced by 'o'.
| | |
|
Search && Replace string:
':' separates two commands
'=' separates the search from the replace string
'\' Escape symbol
'\\' the '\' symbol itself
'\n' newline
'\t' tabulator
'\:' ':' (w/o special meaning)
'\=' '=' (--- " ---)
'\?' '?' (--- " ---)
'\*' '*' (--- " ---)
Search string:
'?' single letter wildcard
'*' multi letter wildcard
Replace string:
'?'
inserts the character which matched the corresponding single letter wildcard ('?') in the search string. Inserts a '?' if there is no corresponding wildcard. Does not apply if a digit or '(' follows.
'?n'
inserts the character which matched the n'th single letter wildcard in the search string. Inserts a '?' if there is no corresponding wildcard. n = { 1,...,9 }
'*'
inserts the substring which matched the corresponding multi letter wildcard ('*') in the search string. Inserts a '*' if there is no corresponding wildcard. Does not apply if a digit or '(' follows.
'*n'
inserts the substring which matched the n'th multi letter wildcard in the search string. Inserts a '*' if there is no corresponding wildcard. n = { 1,...,9 }
'*(key)'
inserts the value of the database field named 'key' (or an empty string, if value is empty or missing)
'*([key]#default)'
inserts the value of the database field named 'key' (or 'default', if value is empty or missing)
'*([key]\:SRT)'
reads the value of the database field named 'key', applies the SRT on that value and inserts the result.
'*([key]|/REG/)'
reads the value of the database field named 'key', applies the ´Regular Expressions (REG)´ REG on that value and inserts the result. Also allows replace by regular expression using '/REG/replace/'.
Notes:
-
all above '*(key...)'-constructs read the content of DB field 'key'.
-
an empty string is used instead, if
-
the field does not exists, or
-
no fieldname is specified. Skipping the fieldname is possible where '[key]' is used in the description above.
-
'?(key...)' does the same as '*(key...)'
-
the SRT, ACI and REG expressions used in '*(key...)' require escaping of the characters ':', '=', '\', '*' and '?' by prefixing a '\'. Nesting SRT expressions require additional levels of escaping (i.e. ':' -> '\:' -> '\\\:' -> '\\\\\\\:').
-
if an error occurs, the error message is inserted as result. When used for ´Node Display Setup (NDS)´ such an error often gets truncated. Increasing the width of the display field helps to see the whole error message.
| | |
|
Below you find some examples of SRT expressions.
'p?r=p?w'
replaces all 'par' to 'paw', 'pbr' to 'pbw', 'pcr' to 'pcw', ...
'p??r=p?2?1r'
swaps the two letters between p and r
'a*=b*'
replaces only the first 'a' by 'b'
'a=b'
replaces all 'a' by 'b'
'?* *=?. *2'
replaces the first word by its first letter + '.'
'\:=\n'
replaces all ':' by <newline>
'*=* *(key1)'
appends the database field <key1>. If <key1> does not exist, append a single space.
'*=* *(key1):* =*'
appends the database field <key1>. If <key1> does not exist, append a single space. The second expression removes such a trailing space again.
'*=* *(key1#no info)'
appends the database field <key1>. If <key1> does not exist, then append 'no info'.
'*=*(key2\: =)'
replace the whole input with the value of 'key2', with all spaces removed.
'*=*(key2|remove(.-))'
replace the whole input with the value of the database entry 'key2', with all '.' and '-' characters removed.
| | |
|
Be careful when search or replace string contain special characters (such as ':'). Avoid to write too complicated commands.
| | |
|
|