Java Reference
In-Depth Information
1,$s/Tryout/Sample/g
Will make the substitution in that method name.
TIP
Remember to precede these commands with a colon (“ : ”) to put you into ex
mode which puts your cursor on the status bar of the window.
2.2.3
The substitution command really becomes powerful when you start using reg-
ular expressions. Our examples so far have only had plain alphanumeric charac-
ters between the slashes of the substitution. But other characters take on special
meanings inside the search and replace strings. Table 2.1 shows just a few.
From this small collection we can do some useful things. We show just a
few in Table 2.2. All commands begin with :1,$ to say that the substitution
will be attempted from the first through the last line of the file. 3 You could use
a smaller range for any of these substitutions, as we discussed above.
The Joy of Regular Expressions
Table 2.1 Regular expression character meanings
Character
Meaning
The beginning of the line.
^
The end of the line.
$
Any single character.
.
Zero or more repetitions of the previous expression.
*
One or more repetitions of the previous expression.
+
Any of the characters inside the brackets will match—e.g., [abc] matches any
of a , b , c . Ranges are allowed too—e.g., [a-z] .
[]
When used on the right-hand side, stands for whatever was found with the
search string on the left-hand side (for an example, see Table 2.2).
&
3. Note that % is valid substitute for 1,$ .
Search WWH ::




Custom Search