I'm looking at this
One use of
regexp-quote
is to combine an exact string match with context described as a regular expression. For example, this searches for the string that is the value of string, surrounded by whitespace:(re-search-forward (concat "\\s-" (regexp-quote string) "\\s-"))
and wondering how to adapt it to do simply go through the file and search for a word that is surrounded by one or more spaces, i.e., whitespace. I'd like to do it as a regex search in the minibuffer. Tried Search/Regex Forward from the menu, also M-x :
to type it as a command in the minibuffer -- all to no avail. Once again, I'm lost in a "guess-and-test" loop.
isearch-forward-regexp
by any chance? It is bound toC-M-s
and works just likeisearch
except that your input is treated as a regexp instead of a string. You can type\s-foo\s-
to it to search for whitespace delimitedfoo
.isearch
itself can look for a space delimitedfoo
by just typing the literal spaces aroundfoo
.isearch-forward-regexp
. In my OP, I tried(re-search-forward (concat "\s-" "word" "\s-"))
with M-: in the command line -- to no avail. Then I tried(re-search-forward (concat "\\s-" (regexp-quote "word") "\\s-"))
which did work. A learning experience...."\s-"
and in the other you used"\\s-"
. See emacs.stackexchange.com/a/55604/454 regarding backslashes in double-quoted strings.