try-completion tests whether a given string can be completed against a given set of completions (e.g. strings).
buffer-list provides the list of buffers.
buffer-name returns the name of a given buffer.
(defun matches-a-buffer-name? (name)
"Return non-nil if NAME matches the name of an existing buffer."
(try-completion name (mapcar #'buffer-name (buffer-list))))
try-completion also accepts an optional
PREDICATE argument, which you can use to impose a particular kind of testing, e.g., a particular kind of matching.
C-h f try-completion tells you, part:
Return common substring of all completions of
Test each possible completion specified by
to see if it begins with
STRING. The possible completions may be
strings or symbols. Symbols are converted to strings before testing,
All that match
STRING are compared together; the longest initial sequence
common to all these matches is the return value.
If there is no match at all, the return value is
For a unique match which is exact, the return value is