Emacs: How to copy regular expressions?

I am just trying to search / highlight text in a buffer with a regular expression and copy it. I donโ€™t need the whole line, only matches. Any ideas?

I have a large number of lines of text containing the tags "[12345] [09876]" and I want a regular expression copy all the tags.

eg.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit [12345][09876], sed diam nonummy [12345][123456] nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud [54321][09876] exerci tation ullamcorper suscipit lobortis nisl ut aliquip [23451][09656] 
+4
source share
1 answer

Yes, incremental search does not move the position of the point, so yank does not copy the match.

The simplest solution is probably the following:

Define a function that copies the search match:

 (defun copy-isearch-match () (interactive) (copy-region-as-kill isearch-other-end (point))) 

And add it to the search mode map

 (define-key isearch-mode-map (kbd "Mw") 'copy-isearch-match) 

Then by doing Mx isearch-forward-regexp , you can press Mw to copy the match.

+6
source

Source: https://habr.com/ru/post/1439438/


All Articles