xah talk show 2022-08-04 emacs regular expression

- https://youtu.be/VBGvGFmo1ps
- xah talk show 2022-08-04 emacs regular expression
tutorial on emacs regular expression.
- what's regex
- why not wildcard (glob). try jpg|png. demo in PowerShell.
- simple example of regex
- emacs regex, by interactive command, or in emacs lisp. there are different.
- emacs regex commands. best way to test regex.
- emacs regex syntax basics.
- regex in emacs lisp.
- best way to test regex in emacs lisp.
- ways to convert regex from command to emacs lisp string.
- Emacs Lisp Toothpick Syndrome
- Emacs: Regex Tutorial
- PowerShell: String Wildcards
- PowerShell: List Files by Name Pattern
most simple regular expression syntax/pattern
.
→ any character[abcx]
→ any of the chars a b c x[a-z]
→ any of the chars a to z[0-9]
→ any of the digits 0 to 9
+
→ one or more of the previous pattern[a-z]+
→ match a sequence of lower case english alphabet
\(regex\)
→ capture the 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"