Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Regular Expressions 2005.pdf
Скачиваний:
95
Добавлен:
17.08.2013
Размер:
25.42 Mб
Скачать

Chapter 12

How to carry out search operations and search-and-replace operations in OpenOffice.org Writer

How to use the POSIX character classes, which are supported in OpenOffice.org Writer

The User Interface

OpenOffice.org Writer’s user interface is different in a number of ways from that of Microsoft Office. However, as in Word, the Ctrl+F shortcut brings up the Find & Replace dialog shown in Figure 12-1.

Figure 12-1

To use regular expressions in OpenOffice.org Writer, you have to check the Regular Expressions check box toward the bottom-left corner of the dialog box. OpenOffice.org’s default behavior is to conduct caseinsensitive regular expression matches. To match regular expressions case sensitively, you must check the Match Case check box as well as the Regular Expressions check box. Depending on what you have been doing in OpenOffice.org Writer, you may sometimes find that the Match Case check box is checked when you open the Find & Replace dialog box. If you expect a default case-insensitive match and don’t notice that the Match Case check box is checked, the matches may not be those you expect. The Regular Expressions check box is, in my experience, always unchecked when you first open the Find & Replace dialog box. However, if you have several OpenOffice.org windows open, the settings in the Find & Replace dialog box for one document may carry over when you open the Find & Replace dialog box in another document.

If the Regular Expressions check box is checked, the Whole Words Only check box is grayed out. OpenOffice.org Writer provides metacharacters, described later in the chapter, which match the beginning- of-word position and the end-of-word position, allowing matches using regular expressions to be made only on whole words (more strictly, on sequences of word characters).

As you have seen in examples in earlier chapters, the Find All button is a very convenient way to find all matches for a particular regular expression pattern. However, you must be careful in interpreting the effect of the Find All button in certain circumstances. For example, suppose that you have multiple successive numeric digits, as in several lines in the following sample (Numbers.txt):

282

Regular Expressions in StarOffice/OpenOffice.org Writer

A123

2345

9876

12ABC345

999

When Find All is clicked, the pattern [0-9]+ in the Search For text box will cause all numeric digits to be matched, as shown in Figure 12-2. However, using the Find All button doesn’t make it clear whether matching is greedy or lazy — in other words, whether a single matching process matches one digit or several.

Interpreting the matches is uncertain if you are unaware that in OpenOffice.org Writer matching is always greedy. If you are uncertain about exactly what is being matched by a pattern, successive clicks of the Find button are useful to help you be sure what the pattern is matching on any one occasion.

This uncertainty is present only when using simple patterns. In most (perhaps all) real-life patterns, the ambiguity isn’t a problem.

Figure 12-2

283