Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Appendix C (continued)

Regular and Selection Expression Characters

  Beginning of file, beginning of line  [Option-8]

The operator means beginning of file or beginning of line.

When occurs by itself in a command, it means beginning of file. For example, the command

Find •

places the insertion point before the first character of the file in the target window. Likewise, the command

Find •:/main/

selects all the text from the beginning of the file to the first occurrence of "main".

When you use at the beginning of a selection expression, it matches the expression only when it occurs at the beginning of a line. For example, the command

Find /•main/

matches any line that begins with "main", but not a line that begins with a space and then "main". The beginning of a line is either the first character after a return or the beginning of the file.

§  Current selection  [Option-6]

The § character specifies the current selection in the target window, unless you specify a window name in your command. For example, the command

Print §

prints the text that is currently selected in the target window. The command

Replace § ∂n

replaces the current selection in the target window with a return character.

To specify the current selection in a window other than the target window, use the window name, then a period, then the § character in your command, as in

Catenate Test.§ > Log

This command copies the current selection in the window named Test to the file Log.

∞  End of file, end of line  [Option-5]

The ∞ character can mean end of file or end of line. For example, the command

Find ∞

moves the insertion point to the end of the file. When the ∞ character appears as the last character of a selection expression, it means end of line. For example, the command

Find /main∞/

finds the string "main" only if it appears at the end of a line. This command would not find the string "main" followed by a space at the end of a line. The end of a line is either the last character of a line before the return, or the end of the file.

:  Everything between two selections

When used between two selection expressions, the : character specifies that you want to select everything between and including the two selections. For example, the command

Find /alpha/:/omega/

selects all the text between the strings "alpha " and " omega ", including both strings. The command

Find •:∞

selects all the text from the top to the bottom of the file.

¡n  Move backward  [Option-1]

When followed by a number, the ¡ operator moves the insertion point backward from its current position or from the beginning of the current selection. The ¡ operator can move the insertion point backward by lines or by characters.

When you use the ¡n notation by itself in a command, the insertion point moves backward by lines. For example, the command

Find ¡5

moves the insertion point backward five lines from its current position or the beginning of the current selection, and then it selects the entire line. When you use two adjacent ¡n notations in a command, the first moves backward by lines, and the second moves backward by characters. For example,

Find ¡2¡2

moves the insertion point two lines backward, selects the entire line, then moves two characters back at the end of the previous line.

When you combine ¡n with a selection expression, the insertion point moves backward by characters. For example, the command

Find /one/¡4

finds the string "one", then places the insertion point four characters before the "o".

!n  Move forward

When followed by a number, the ! operator moves the insertion point forward from its current position or from the end of the current selection. The ! operator can move the insertion point forward by lines or by characters.

When you use !n by itself, the insertion point moves forward by lines. For example, the command

Find !5

moves the insertion point forward five lines from its current position or the end of the current selection, and then it selects the entire line. When you use two adjacent !n notations in a command, the first moves forward by lines, and the second moves forward by characters. For example,

Find !2!2

moves the insertion point two lines forward, then moves two characters forward on the next line.

When you combine !n with a selection expression, the insertion point moves forward by characters. For example, the command

Find /one/!4

finds the string " one", then places the insertion point four characters after the " e".

¬  Not in the following list  [Option-L]

When used inside brackets and before a character range, the ¬ character specifies that the selection expression should match any character not in the character range. For example, the command

Find /[¬a-z]/

finds any nonalphabetic character.

Note
By default, searches are not case sensitive. To specify case-sensitive searches, you can either set the MPW Shell variable {CaseSensitive} to a nonzero value or click the checkbox labeled Case Sensitive in the dialog boxes displayed by the Find and Replace menu items. •

The ¬ character is also the logical NOT operator (see the ¬ Logical NOT entry).

+  One or more occurrences

You can add a + character to a regular expression to specify that the expression should be matched when it occurs one or more times in succession. You would type the + character within the forward or backward slashes that enclose the regular expression, as in

Find /o+/

which finds any sequence of one 0 or more: 0, 00, 000, and so on. The command

Find /[a-z]+/

uses a scan set and matches any sequence of one or more uppercase or lowercase letters between A and Z, that is, any word. You could replace a string of one or more tabs with one tab by entering

Replace /∂t+/ ∂t

Be sure to place the + character inside the slashes that enclose the selection expression.

See the + Addition entry for information on the + character as the addition operator.

∆  Place insertion point  [Option-J]

The ∆ operator places the insertion point before or after a selection if you place ∆ before or after the selection expression in your command. The command

Find ∆/one/

selects the word one and places the insertion point before the o. However, the command

Find /one/∆

selects one and positions the insertion point after the e.

You can move the insertion point to the beginning of the current selection by using the ∆ operator with the § character, as in

Find Ƥ

-  Specify a range of characters

Within brackets that are used to enclose a scan set, the hyphen marks a range of characters. A regular expression that specifies a range of characters matches any character in the range. You specify a character range by typing the first character of the range, then a hyphen, then the last character of the range. For example,

Find /[a-c]/

finds the first occurrence of either a, b, or c, in lowercase or uppercase.

Note
By default, searches are not case sensitive. To specify case-sensitive searches, you can either set the MPW Shell variable {CaseSensitive} to a nonzero value or click the checkbox labeled Case Sensitive in the dialog boxes displayed by the Find and Replace menu items. •

Both the character ranges

[A-Z]
[a-z]

select the first uppercase or lowercase letter after the insertion point. Likewise, the pattern

[0-9]

selects any single digit. You can combine ranges within a single set of brackets, as in

Replace /[a-z0-9]/ "?"

which selects the first letter or number after the insertion point and replaces it with a question mark.

See the - Subtraction, sign change entry for information on the - character in arithmetic expressions.

®  Tag an expression  [Option-R]

To tag a selection expression or part of a selection expression so that you know what string matched it, you can use the ® operator. To use the ® operator, first place parentheses around the part of the selection expression you want to tag, then type the ® followed by a number between 0 and 9. Be certain to place the ®n notation within the slashes.

For example, the command

Find /([0-9])®1/

finds any number between 0 and 9 and tags the text that is selected with ®1. Once you select some text and then tag it, you can refer to it later in the same command. For example, you can enter

Replace /([0-9]+)®1,([0-9]+)®2/ "®2,®1"

to reverse two numerals separated by a comma and change 1,3 to 3,1. The command has two parameters. The first is a pattern that Replace searches for, and the second is the string that replaces it. For more information on the ® character, refer to the chapter "Editing With Commands" in Introduction to MPW.

*  Zero or more occurrences

The * character specifies that the characters in a regular expression should be matched when they occur zero or more times in succession. For example, the command

Find /and[' ']*/

finds the string and when it is followed by zero or more spaces. In other words, it finds and when it is a whole word or part of a word. Be sure to place the * character inside the slashes that enclose the selection expression.

 
 


Last Updated July 2000