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

Chapter 6

The \b Syntax

The \b metacharacter can match a word boundary at either the beginning or end of a word, as illustrated in the following Try It Out section.

Try It Out

The \b Metacharacter

1.Open PowerGrep, and enter the pattern \bA in the Search text box.

2.Enter the text C:\BRegExp\Ch06 in the Folder text box.

3.Enter the filename BoundaryTest.txt in the File Mask text box.

4.Click the Search button, and inspect the results in the Results area, as shown in Figure 6-18.

Figure 6-18

How It Works

The pattern \bA is identical in effect to \<A. It means a word boundary followed by an uppercase A. In theory, the meaning isn’t identical, because \<A means the following:

Match a beginning-of-word word boundary followed by an uppercase A.

Whereas \bA means the following:

Match a word boundary that can be a beginning-of-word word boundary or an end-of-word word boundary followed by an uppercase A.

In practice, a word boundary followed by an alphabetic character must be a beginning-of-word word boundary. One of the exercises will ask you to match end-of-word word boundaries using the \b metacharacter.

The \B Metacharacter

The \B metacharacter is the opposite of the \b metacharacter. The \B metacharacter matches a position that is not a word boundary.

168