Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 610025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:37:48+00:00 2026-05-13T17:37:48+00:00

In Emacs how can I easily copy all lines matching a particular regex? Preferably

  • 0

In Emacs how can I easily copy all lines matching a particular regex? Preferably highlighting the matching lines as I type.

occur gets partway there by coping them into a buffer, but it adds lots of extra stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:37:49+00:00Added an answer on May 13, 2026 at 5:37 pm

    How about this:

    (defun copy-lines-matching-re (re)
      "find all lines matching the regexp RE in the current buffer
    putting the matching lines in a buffer named *matching*"
      (interactive "sRegexp to match: ")
      (let ((result-buffer (get-buffer-create "*matching*")))
        (with-current-buffer result-buffer 
          (erase-buffer))
        (save-match-data 
          (save-excursion
            (goto-char (point-min))
            (while (re-search-forward re nil t)
              (princ (buffer-substring-no-properties (line-beginning-position) 
                                                     (line-beginning-position 2))
                     result-buffer))))
        (pop-to-buffer result-buffer)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I copy a line 10 times easily in Emacs? I can't find
How can I write an Emacs Lisp function to find all hrefs in an
In Emacs you can use the untabify function to convert all the tabs into
I have a text file. Can Emacs select text based on regex and put
Possible Duplicate: How can I more easily switch between buffers in Emacs? While working
How can I use emacs string-insert-rectangle operation to add a vector of numbers to
How can I make a cross-platform emacs command that opens another instance of emacs
I can't get python-mode working in Emacs on Mac OS X (I am a
I can't get 'remember' to work in org-mode of emacs. I'm on snow leopard.
How can I get a tabbed interface in carbon emacs which corresponds to one-tab-per-buffer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.