I use M-x re-builder a lot. Its an interactive regular expression builder that really helps build proper regexps and is an excellent learning tool.
However, in using it, I found myself repeating a particular workflow: - build regexp in re-builder - copy it - run query-replace-regexp - paste regexp as the search - type in the replacement - press return and off you go
This was a lot of repeated work, so I wrote a function, which I bind to a key in reb-mode-map (C-c M-%, since plain old M-% is query-replace) which can be run in the re-builder buffer to automatically search the target buffer (the one that re-builder matches as you build) for the regexp you built, and replace it with a string, which is the only prompted argument of the function.
That may all sound complication, but its not. The workflow becomes: - build regexp in re-builder - run reb-query-this-regexp (C-c M-%) - type in the replacement - press return and off you go
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17