[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select/highlight and *copy* matches of some regex

From: Daniel Martín
Subject: Re: Select/highlight and *copy* matches of some regex
Date: Tue, 28 Jun 2022 11:29:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin)

Joost <> writes:

> On Mon, 27 Jun 2022, at 18:12, wrote:
>> Not a direct answer to your question, but perhaps similar. If you
>> can live with selecting /lines/ containing a match, there's "occur"
>> (M-x occur).
> Sorry, I meant to mention that, but I forgot. No, selecting lines is not an 
> option, because it's the non-matching parts of each line that I'm trying to 
> get rid of.
> In my particular use case, I'm trying to clean up a file that looks something 
> like this:
> ```
> blah blah lang=en bla
> lang=de
> lang=fr blah blah
> blah lang=pt
> ```
> The part I'm interested in is "lang=xx", the rest needs to be
> removed. Each line contains this part (with different language codes),
> but may contain more text, which is irrelevant to me. There's no
> pattern to the irrelevant part, it can basically be any text.
> I can highlight them with `highlight-regexp`, search for them with isearch, 
> but there doesn't seem to be a straightforward way to copy or kill them...

You can pass the universal argument to occur to only show the matches
for the regexp, excluding the rest of the line.  For example:

C-u C-s REGEXP C-u M-s o

This will show an *Occur* buffer with only the matching parts of REGEXP
in the current buffer, which you can save to a file, etc.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]