xah talk show 2022-08-04 emacs regular expression

xah talk show 2022-08-04 emacs regular expression

tutorial on emacs regular expression.

most simple regular expression syntax/pattern

change double quoted numbers to single quote
something "997"  "cats"
and "70" "dogs"
in emacs, if you want to include a newline char, you cannot use \n, you have to type Ctrl+q Ctrl+j for literal newline char

replace any 2 lines such that the first line is cat, and second line is anything, replace them into one single line

cat
dog

some A
some B

cat
tiger

cat
rabbit

cat
something and something
;; testing regex in emacs lisp

(let ()
  (re-search-forward "\"\\([0-9]+\\)\"")
  (replace-match "'\\1'"))

change "double quoted" numbers to single quote, in emacs lisp
something "228997"  "cats"
and "70" "dogs"