Contents:
Text Wielder is a text editor with an extremely powerful find and replace panel. Text Wielder is also capable of offering a varitey of services through the service menu. If you are interested in using services with Text Wielder see this document here.
SFRL stands for Simple Find and Replace Language. SFRL is used to find and replace text in a document much like the find panel you will see in many other applications such as Text Edit. However, SFRL is much more powerful because, altough it can do things as simple as finding the letter "a" and replacing it with the letter "b", it can also use SFRL find statements which wrap regular expressions and SFRL replace statements which are JavaServer Pages*(JSPs). Also, with the use of services, Text Wielder can use SFRL to not only modify text but to do things such as using the text to create a URL to open in your web browser or generate and run an Applescript.
A SFRL "program" is called a script. A SFRL script is simply a document with a find and replace statement. You can create SFRL scripts by opening Text Wielder and choosing the "New SFRL Script" menu item in the "File" menu. Below is the SFRL Script Window with a simple find and replace statement:
You can see that the find statement is simply the word "Hello" and the replace statement is"Hi there". If you create a new text document in Text Wielder(use "New Text File" in the "File" menu) and type some text with the word "Hello" in it, you can use the "Replace All" button to replace all occurrences of "Hello" with "Hi there".
Options
Matching
Replace All Scope
Toolbar Items
SFRL allows you to quickly and easily manipulate text, this short example will give you a brief introduction to the basics of SFRL.
Let's say you have a list of people's names such as the text given below:
Bohr, Niels
Einstein, Albert
Franck, James
Guillaume, Charles
Millikan, Robert
We will call this the Input Text.
Now, let's say we would like to change these names so they read as first name first, last name second. Let's also say we would want each name to be preceded by "Name: "
So, for example, we would like to change "Einstein, Albert" to "Name: Albert Einstein"
Instead of manually rearranging the text, which is tedious and could be very time consuming if we had say a list of 1000 names, we will use SFRL to do the job for us.
We will first create the SFRL Find Statement. This is similar to the find mechanism found in most text editors with one important exception: find variables.
Below is our find statement:
<^lastName^>, <^firstName^>
In the find statement above, <^lastName^> and <^firstName^> are both what we call find variables. The comma followed by a space between the two find variables is just text.
We will now create the SFRL Replace Statement. This is similar to the find statement.
Below is our replace statement:
Name: <%= firstName %> <%= lastName %>
As you can see we use the two variables which we defined in the find statement but we have rearranged them to give the desired output. We have also added the text 'Name: ' before each name.
Below is the Output Text after we have run our SFRL statements with the above Input Text:
Name: Niels Bohr
Name: Albert Einstein
Name: James Franck
Name: Charles Guillaume
Name: Robert Millikan
Find Statement | Description |
a | Match the letter "a". |
<^text^> | Match any text except new lines. |
<^text multiLine^> | Match all of the text, including multiple lines. |
<^lastName^>, <^firstName^> | lastName will match everything before ", "(thats comma space) firstName will match everything after that. |
<^fruit "apple" OR "orange"^> | Match "apple" or "orange". |
<^aWord word^> | Match a single word. |
<^text word OR "?"^> | Match a single word or a question mark. |
<^zipcode re = "[0-9]{5}(-[0-9]{4})?"^> | Match a zipcode in the form of five digits optionally followed by a dash and four more digits. |
<^zipcode optional re = "[0-9]{5}(-[0-9]{4})?"^> | Optionally match a zipcode in the form of five digits optionally followed by a dash and four more digits. |
Name:<^whiteSpace^><^name^> | Match "Name:" followed by any amount of white space, followed by some text. |
Syntax
SFRL Find statement can be any combination of plain text, find variables, and comments.The syntax for find variables and comments is given below:
findVariable -> <^identifier [optional] [keywordExpression [or keywordExpression]*]^>
keywordExpression -> "String literal"
word
multiLine
re = "Perl 5 Regular Expression"
comment -> <%-- Comment Text --%>
Pre-defined Find Variables
Reserved Find Variable Name | Description |
tab | A tab character. \t |
space | A space character. |
whiteSpace | Any amount of tabs and/or spaces. |
newLine | A new line. Either \n, \r, or \r\n |
lineFeed | A line feed character. \n |
carriageReturn | A carriage return character. \r |
comma | A comma character. |
period | A period character. |
doubleQuote | A double quote character. " |
singleQuote | A single quote character. ' |
colon | A colon character. : |
semicolon | A semicolon character. ; |
backslash | A backslash character. \ |
forwardslash | A forwardslash character. / |
Examples
Replace Statement | Description |
a | Output the letter "a" |
<%= text %> | Output the variable named "text" which was defined in the find statement. |
Hello <%= name %> | Output "Hello " followed by the variable named "name" which was defined in the find statement. |
<%= text.toUpperCase() %> | Output the variable named "text" in all uppercase. |
Length of text:<%= text.length() %> | Output "Length of text:" followed by the length of text. |
<%= date %> | Output the current date(e.g. 11/12/2001) |
Syntax
SFRL replace statements are JSPs**. Most often for replace statements you will use a mixture of plain text and "Expressions". An example of an expression is:
<%= variableName %>
This simply outputs the text that matched variableName in the find statement. You can also modify the variable in expressions like:
<%= variableName.toUpperCase() %>
Complex replace statements are also possible and you have full access to the Java API. The below example sorts lines.
find:<^theText multiLine^>
replace:
You also have access to two other classes, StringUtilites and SOAPHelper. StringUtilities provides some methods for manipulating Strings and SOAPHelper simplifies using the Apache SOAP API(which is also available to you).
For more information on JSP syntax see http://java.sun.com/products/jsp/tags/11/tags11.html
Pre-defined Replace Variables
Reserved Replace Variable Name | Description |
tab | A tab character. \t |
space | A space character. |
newLine | A new line charachter. \n |
lineFeed | A line feed character. \n |
carriageReturn | A carriage return character. \r |
comma | A comma character. |
period | A period character. |
doubleQuote | A double quote character. " |
singleQuote | A single quote character. ' |
colon | A colon character. : |
semicolon | A semicolon character. ; |
backslash | A backslash character. \ |
forwardslash | A forwardslash character. / |
date | The current date. |
time | The current time. |
Text Wielder uses services extensively. See the Services documentation for more information.
* SFRL is a trademark of Tinnef Software
** JavaServer Pages and JSP is a trademark of Sun Microsystems, Inc.