Lesson 6

Position Matching

You’ve now learned how to match all sorts of characters in all sorts of combinations and repetitions and in any location within text. However, it is sometimes necessary to match at specific locations within a block of text, and this requires position matching, which is explained in this lesson.

Using Boundaries

Position matching is used to specify where within a string of text a match should occur. To understand the need for position matching, consider the following example:

Text

The cat scattered his food all over the room.

RegEx

cat

Result

The cat scattered his food all over the room.

Analysis

The pattern cat matches all occurrences of cat, even cat within ...

Get Learning Regular Expressions, First Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.