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 7759613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:40:29+00:00 2026-06-01T13:40:29+00:00

What is the correct regex for filtering multiple-lined blocks of text that end with

  • 0

What is the correct regex for filtering multiple-lined blocks of text that end with #tags? My file looks like this:

Text block 1:
- something
- something
- something
#tag1 #tag2

Text block 2:
- somethingelse
- somethingelse
#tag2

Text block 3:
- really interesting stuff
- really interesting stuff
#tag1

etc

These great tips pointed me to using \_.. Hence, for filtering out both blocks containing #tag1, I came up with this:

\_.\{-}#tag1.*

That, however, only gives me Text block 1. Instead of pointing me further to Text block 2 (which also contains the tag), the cursor starts moving downwards line-by-line.

Where am I going wrong? Thanks for any explanations!


EDIT: A follow-up on how to create a multi-command for this kind of query is here.

  • 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-06-01T13:40:31+00:00Added an answer on June 1, 2026 at 1:40 pm

    This works for me if you want to match every line in the block (use to yank all text in the matching blocks into a buffer)

    ^\(.\+\n\)\{-}#.*tag1
    

    So you could do

    g/^\(.\+\n\)\{-}#.*tag1/d A
    

    To delete all text blocks(change d to y if you want to yank them instead, of course) that end with a #tag1 and yank them into register A, then "ap to paste them all (or <C-r>a in insert mode)

    This lets me jump to the first line of each block that ends with tags containing tag1.

    \(\%^\|^\n\)\zs.\(.\+\n\)\{-}#.*tag1.*$
    

    The problem with

    \_.\{-}#tag1.*
    

    Is that while you’re using {-} to be non-greedy, it’s still always going to match as long as there is a line that has #tag1 below the current line that you’re on. Using _.* or _.{-} can be pretty dangerous. For example when you are on the line “Text block 2:”

    Text block 2:
    - somethingelse
    - somethingelse
    #tag2
    
    Text block 3:
    - really interesting stuff
    - really interesting stuff
    #tag1
    

    You get a match for the entire range Text block 2 until #tag1 after text block 3.

    If instead you had

    Text block 3:
    - really interesting stuff
    - really interesting stuff
    #tag1
    
    Text block 2:
    - somethingelse
    - somethingelse
    #tag2
    

    You would only match lines in Text block 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the current text that i've but the regex isn't correct to split
I would like to know the correct regex for matching multiple MAC addresses separated
Looks like a simple task - get a regex that tests a string for
If there is one that could handle this, what would be the correct regex
What is the most correct regular expression (regex) for a UNIX file path? For
can i somehow compare two numbers in regex? i want regex that is correct
PCRE: /\A[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[a-z]{2,4}|museum|travel)\z/i POSIX: /^[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i This regex is correct in every way for my needs
Trying to get the correct regex for this - only letters, spaces, hypens, and
What is the correct regex for getting a string that contains only letters, must
I have a text file that needs to be parsed correctly. The text file

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.