Next: , Up: pregexp syntax   [Index]


51.3.1 Basic assertions

The assertions ^ and $ identify the beginning and the end of the text string respectively. They ensure that their adjoining regexps match at one or other end of the text string. Examples:

(pregexp-match-positions "^contact" "first contact")
⇒ #f

The regexp fails to match because contact does not occur at the beginning of the text string.

(pregexp-match-positions "laugh$" "laugh laugh laugh laugh")
⇒ ((18 . 23))

The regexp matches the last laugh.

The metasequence \b asserts that a word boundary exists.

(pregexp-match-positions "yack\\b" "yackety yack")
⇒ ((8 . 12))

The yack in yackety doesn’t end at a word boundary so it isn’t matched. The second yack does and is.

The metasequence \B has the opposite effect to \b: It asserts that a word boundary does not exist.

(pregexp-match-positions "an\\B" "an analysis")
⇒ ((3 . 5))

The an that doesn’t end in a word boundary is matched.