You could always use one of the character classes. I would say use [:blank:]
when the usage context is textual, and use [:space:]
when it is programmatic, i.e. plain text vs source code.
When entered interactively, this seems to work: =[[:blank:]^J]*
. You can enter ^J
by just quoting your newline: C-q C-j. In elisp the usual \n
works.
I tested interactive use with highlight-regexp
and isearch-forward-regexp
, and elisp use with M-: (search-forward-regexp "=[[:blank:]\n]*")
.
Edit: (to clarify comments)
If you compare the docs for \s
with that for [[:blank:]]*
(linked above), the latter is a superset. If your use case considers characters like tab as whitespace, you should use the latter, if not, \s
should be fine.
A couple of examples:
- Say you are looking for a name (variable, function, etc) in C++ source,
\s
would be sufficient.
- You want to change the indentation in a plain text notes file,
[:blank:]
would be better suited.
Although, this may not be a hard and fast rule, as many source files can contain tabs as whitespace. That's exactly why this is for you to judge case by case.
\s
expands to a space and\n
expands to a newline. You need to escape the backslash if you want to use it as character in the regexp. Considering that the regexp with the space syntax class matcher in it looks like"=\\s-*"
. Note that\\s-
does not work in character classes like[\\s-\n]
. Use[[:space:]\n]
instead."\s*"
is the string" *"
. It matches spaces (char-code 32) and only spaces. If you want to match all characters belonging to the whitespace syntax class you should use"\\s-*"
instead. Note the double-backslash which represents one backslash character in the string/regexp.