Coding Regexps Can Also Save the Day
Coding Macros Can Save the Day presented the case for macros as powerful coding helpers. No regular expressions were used, though, making it easier for the reader to follow mechanical manipulations.
Today, we’ll tackle the same boring task of building a switch/case statement from constants. But this time, GNU Emacs regexps will be employed.
The nice and flexible regexp-replace command does the job, captured on the small recordMyDesktop screencast below:
Note that Emacs regexing is a little strange at first, if compared to “flavors” offered by modern programming languages/environments (by the way, newlines can be embedded in a command/regexp with ‘C-q C-j’ sequence).