help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Regex to match lines with a specific number of words


From: Thibaut Verron
Subject: Re: Regex to match lines with a specific number of words
Date: Sat, 23 Apr 2022 22:58:48 +0200

Hi,

The group [:space:] also matches newline characters. So your search has
exactly one match, spanning many lines.
You can use [:blank:] instead to match spaces and tabs only, for the
separator.

It's probably better to keep [^[:space:]] for the first group, you wouldn't
want to start matching newlines there.

Best wishes,
Thibaut

Le sam. 23 avr. 2022 à 22:39, Joost Kremers <joostkremers@fastmail.fm> a
écrit :

> Hi all,
>
> I've been trying to come up with a regex that will match any line
> containing at
> least 30 words in order to kill them from the buffer (preferably with
> `kill-matching-lines`, because I need to move the lines to another buffer.)
>
> Frustratingly enough, I have not been successful. Since "word" here can be
> interpreted very broadly, I thought this would be easy. Any sequence of
> non-whitespace characters surrounded by whitespace can be considered a
> "word"
> (even if it's a number of some special character such as & or #.) So I did
> this:
>
> \([^[:space:]]+[[:space:]]+\)
>
> This seems to capture a word (in the above sense) plus any following white
> space
> well enough.
>
> But when I try to modify the regex to only match those lines that repeat
> this
> pattern at least 30 times, it fails:
>
> \([^[:space:]]+[[:space:]]+\)\{30,\}
>
> Passing this to `flush-lines` simply deletes everything in the buffer
> starting
> at point, telling me it "[d]eleted 1 matching line", even though (many)
> more
> lines were deleted. Adding ^ and $ around the regex didn't have any effect.
>
> So what am I doing wrong here?
>
>
> --
> Joost Kremers
> Life has its moments
>
>


reply via email to

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