Elisp: Regex Patterns and Syntax Table

By Xah Lee. Date: . Last updated: .

Here's a demo, that some regex depend on syntax table.

;; here's a demo, that some elisp regex pattern depend on elisp syntax table.

;; save this file as test.el, and open it.
;; M-x emacs-lisp-mode

;; put cursor right after the paren, and M-x eval-last-sexp
(re-search-forward "[[:space:]]")
;; it'll move cursor to a space

;; now, set space to have word syntax. Eval this
(modify-syntax-entry 32 "w" emacs-lisp-mode-syntax-table)

;; try the search above again. Now it won't find any

After the above, you'll need to restart emacs. Because, now cursor moving commands will consider space as part of word.

See also: Emacs: Regex Tutorial

Elisp Syntax Table

  1. Character Type
  2. Syntax Table Tutorial
  3. Find Syntax of a Character
  4. Modify Syntax Table Temporarily
  5. is Cursor Inside String/Comment
  6. Regex Patterns and Syntax Table
  7. Find Matching Bracket Char

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc