Elisp: Regex Named Character Class and Syntax Table
In emacs
Regular Expression Syntax,
the meaning of some named character class such as [[:word:]] is dependent on the current major mode's
Syntax Table.
this means,
[[:word:]]
may have different meaning in different
Major Mode
Best is just to put the chars you want explicitly in your regex, for example, [A-Za-z0-9]+.
Use
[[:word:]]+
if you need to match letters of western languages and also Chinese characters or Russian characters etc.
Here's a demo, that some regex depend on syntax table.
here's a demo, to show that some emacs regex pattern depend on syntax table. copy and paste this text into a emacs buffer. now set to text-mode by M-x text-mode s------------------------------ put cursor right after the right parenthesis, and M-x eval-last-sexp (re-search-forward "[[:word:]]") · name: MIDDLE DOT codepoint 183 it'll move cursor to the middle dot now set the buffer to fundamental-mode by M-x fundamental-mode repeat the above steps. it'll move cursor to a letter instead.
emacs and elisp regex
- Emacs: Regular Expression
- Emacs: List Matching Lines
- Emacs: Regular Expression Syntax
- Emacs: Regex Backslash in Command Prompt
- Emacs: Case Sensitivity in Text Search Commands
- Emacs: Insert Tab or Newline
- Emacs: Wildcards vs Regular Expression
- Elisp: Regular Expression
- Elisp: Regex Functions
- Elisp: Regex Backslash in Lisp Code
- Elisp: Case Sensitivity (case-fold-search)
- Elisp: Find Replace Text in Buffer
- Elisp: Match Data (Regex Result)
- Elisp: Unicode Escape Sequence
- Elisp: Convert Regex to Lisp Regex String
- Elisp: How to Test Regex
- Elisp: Regular Expression in Lisp Syntax, Rx (Package)
- Elisp: Regex Named Character Class and Syntax Table
- Emacs Regex vs Regex in Python, JavaScript, Java