Search And Replace |
Top Previous Next |
Search and Replace (SAR) This is a powerful feature that will allow you to select a block of text, then perform multiple regex replacements on it.
TextWorx comes with some pre-built SAR functions: •Abbreviations to States Converts abbreviations to States' full names (a simple example of regex to find word boundaries) •States to Abbreviations* Converts states full names to abbreviations and vice-versa •Latin Accentuation Inserts accents into Latin text (an elaborate system of progressive replacement) •Morse Code* Converts English to Morse Code and vice-versa (an example of arrangement of search terms)
Note: To use the SAR Morse Code, you have to first arrange the text with spaces between every character, due to the nature of Morse Code itself. For this you can use 716 Interspace.
SAR is configured by creating an INI file for each function, and these files must be placed in the permutare directory in the TextWorx application folder. You can change the name and location of this folder in the INI file - you would place there a full path to whatever other folder you wish to use. The default folder is called permutare, and it comes with TextWorx. [Preferences]
You can create as many SAR ini files as you like - they will show up automatically in the permutare (sardir) folder. directory when you place them in the
The text before the = is called the INI Key. The text after the = is called the INI Value. The name in [brackets] is called the INI Section. Lines that start with a semicolon ; are comments and TextWorx ignores them, but you can use them to make notes.
[settings]
There are three SAR settings that must be in the [settings] section. •title The TITLE of the SAR function - this is what appears in the Menu. To allow the SAR to be reversible, you must add a * to the end of the TITLE (which also helps you know that in the Menu). •sarmode Case-sensitivity for the search. •regex Whether the searchterms are in regex or plaintext.
If you don't use regex, then the effect is reversible if you hold the shift modifier when you summon the command from the TextWorx Menu. However, SAR does not respect word boundaries, so keep that in mind.
The searchterms and their replacements go in the [keys] section. SAR might freak out though, if you use an = in searchterm (perhaps in a regex) It will probably make SAR think that the replacement starts just after that =, and will use it as part of the replacement... Maybe we'll fix that someday.
There are three modes for SAR, each one can affect the way the search is performed: 1 = Case insensitive 2 = Case sensitive 3 = Multi-case-sensisitve
The gist is this: 1.You select a block of text in your text editor, then select your SAR command. 2.SAR compares each word in the selected text with the SAR searchterms. 3.It makes the first replacement, then searches each word in the modified (including the first, modified searchterm) text block for the second searchterm. 4.If the text has been changed in the first replacement, SAR will still compare it to the second searchterm. In this fashion, you can make progressive replacements (if you are brave, look at the Latin-Accents.ini.
Say we want to find all the state abbreviations and replace them with their full names. Here is the first part of the Abbreviations to States SAR, using regex to detect word boundaries.
[settings]
Unusable Characters (sorry! I haven't figured it out yet.) •; This character will never get replaced and is ignored as a searchterm because it create an INI comment. •" This character will never get replaced and is ignored as a searchterm.
Remember, when creating your SAR, that if the text has been changed in the first replacement, SAR will now compare the replacement to the second searchterm. In this fashion, you can make progressive replacements.
The searchterms do not need to be in alphabetical order. In fact, there are times when you don't want to do this. Consider this shortened version of the States to Abbreviations SAR.
If we put Virginia above West Virginia, all instances of "West Virginia" would be changed to "West VA" and then SAR would never find "West Virginia" again. Therefore, we put West Virginia above Virginia.
Take a peek at the Latin.ini and see how we replace groups of letters, all in a particular order to achieve pretty good (albeit not perfect) Latin accentuation.
[settings] ;If you use the reverse (by pushing control or shift), it is best to do so only on plain lists or single words.
•Put the most unique keys at the top of the [keys] list and the least unique ones at the bottom •Place the longer keys at the top, shorter at the bottom •Prepare the harder searchterms by adding some sort of token at the top, then replace the searchterm that has the token later in the bottom.
|