Elisp: 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
.
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.
Elisp, Regex in Lisp Code
- Elisp: Regular Expression
- Elisp: Regex Functions
- Emacs: Regular Expression Syntax
- 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: Regex in Readable Syntax, Package Rx
- Elisp: Regex Named Character Class and Syntax Table
- Emacs Regex vs Regex in Python, JavaScript, Java