9.3 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:

> (regexp-match-positions #rx"^contact" "first contact")

#f

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

> (regexp-match-positions #rx"laugh$" "laugh laugh laugh laugh")

'((18 . 23))

the regexp matches the last laugh.

The metasequence \b asserts that a word boundary exists, but this metasequence works only with #px syntax. In

> (regexp-match-positions #px"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 (also #px only) has the opposite effect to \b; it asserts that a word boundary does not exist. In

> (regexp-match-positions #px"an\\B" "an analysis")

'((3 . 5))

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