The function that comes to my mind at least would be cl-member
using a string-match-p
test.
Here's a short example that shows how to use it:
ELISP> (setq testing '("an apple" "a pear" "a grape"))
("an apple" "a pear" "a grape")
ELISP> (cl-member "apple" testing)
nil
ELISP> (cl-member "an apple" testing)
nil
ELISP> (cl-member "an apple" testing :test #'string=)
("an apple" "a pear" "a grape")
ELISP> (cl-member "a pear" testing :test #'string=)
("a pear" "a grape")
ELISP> (cl-member "a pear" testing :test #'string-match-p)
("a pear" "a grape")
ELISP> (cl-member "pear" testing :test #'string-match-p)
("a pear" "a grape")
ELISP> (cl-member "xx" testing :test #'string-match-p)
nil
Note that member
and cl-member
doesn't actually return true
but the
sublist that contains the sought element. That in turn will eventually evaluates
to true
in tests, but That's mostly a minor detail.
Edit:
Sean pointed out an important detail about string-match
and string-match-p
:
Regular expression meta-characters in the search string might give an erroneous
result. If that's a problem you could examine the raw sequence instead with
cl-search
:
ELISP> (setq test (list "apple" "pear" "grape"))
("apple" "pear" "grape")
ELISP> (cl-member "ap" test :test #'cl-search)
("apple" "pear" "grape")
ELISP> (cl-member "gra" test :test #'cl-search)
("grape")