Emacs Lisp: Tip: How to Test Regex
One simple way to test regex is to create a file with the following content:
(re-search-forward "yourRegex") big text to search here
or
(let ((case-fold-search nil)) (re-search-forward "\\.jpg")) ;; cat.jpg
save the file as test.el, reopen it, so it opens in emacs lisp mode so you have syntax coloring.
Then, put your cursor to the right of the closing parenthesis, then Alt + x eval-last-sexp
【Ctrl + x Ctrl + e】.
If your regex matches, it'll move cursor to the last char of the matched text.
If you get a lisp error saying search failed, then your regex didn't match.
If you get a lisp syntax error, then you probably screwed up on the backslashs.
Emacs Regular Expression
- Regular Expression
- Regex Syntax
- About Quoting Regex
- Case Sensitivity
- How to Insert a Tab or Newline
- Wildcards vs Regex
- Emacs Regex vs Python, JavaScript, Java