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

  • SEARCH
  • Home
  • 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 201189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:10:38+00:00 2026-05-11T17:10:38+00:00

edit: I need advice on best way to search with regex in vim and

  • 0

edit:

I need advice on best way to search with regex in vim and extract any matches that are discovered.


I have a csv file that looks something like this:

Two fields:

  • id

  • description


0g98932,"long description sometimes containing numbers like
1234567, or 0000012345 and even BR00012345 but always containing text"

I need to search the description field on each row.
If a number matching \d{10} exists in the second field, I want to pull it out.

doing something like :% s/(\d{10})/^$1/g gives me a

Pattern not found (\d{10}) error.

I’ve never learned how to grab and reference a match from a regex search in vim – so that’s part of the problem.

The other part:

I would really like to either.

  1. Delete everything other than the first 7 digit id and the matches.
  2. Copy the id and the matches to another file – or to the top of the current file (somewhere – anywhere just to separate the matches from the unfiltered data).
  • 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-11T17:10:38+00:00Added an answer on May 11, 2026 at 5:10 pm

    The important thing to know about vim regexes is that different levels
    are escaping are required (as opposed to, say, regexes in Perl or Ruby)

    From :help /\m

    after:    \v     \m       \M        \V    matches
                     'magic'  'nomagic'
              $      $        $         \$    matches end-of-line
              .      .        \.        \.    matches any character
              *      *        \*        \*    any number of the previous atom
              ()     \(\)     \(\)      \(\)  grouping into an atom
              |      \|       \|        \|    separating alternatives
              \a     \a       \a        \a    alphabetic character
              \\     \\       \\        \\    literal backslash
              \.     \.       .         .     literal dot
              \{     {        {         {     literal '{'
              a      a        a         a     literal 'a'
    

    The default setting is ‘magic’, so to make the regex you gave worked, you’d
    have to use:

    :%s/".*\(\d\{10}\).*"/\1/
    

    If you want to delete everything other than the first 7 digit id and the matches
    (by which I assume you mean that you want to delete lines without any match)

    :v/^\([[:alnum:]]\{7}\),\s*".*\(\d\{10}\).*/d
    :%s//\1,\2/
    

    The :v/<pattern>/ command allows you to run a command on each line that doesn’t match
    the given pattern, so this just deletes the non-matches. :s// reuses the prior pattern,
    so we don’t have to specify it.

    This transforms the following:

    0g98932,"long description sometimes containing numbers like 0123456789"
    0g98932,"long description no numbers"
    0g98932,"long description no numbers"
    0g98932,"long description sometimes containing numbers like 0123456789"
    0g98932,"long description no numbers"
    0g98932,"long description no numbers"
    0g98932,"long description no numbers"
    0g98932,"long description no numbers"
    0g98932,"long description sometimes containing numbers like 0123456789"
    0g98932,"long description no numbers"
    0g98932,"long description no numbers"
    0g98932,"long description sometimes containing numbers like 0123456789"
    

    into this:

    0g98932,0123456789
    0g98932,0123456789
    0g98932,0123456789
    0g98932,0123456789
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to edit XML files on a small Linux box that we have
I need an advice on best practices for DRYing view code. I have three
I need people's advice as to whether this the best way to achieve what
I need the form that will edit the array of entities and their related
I just realized that there is no best way to hide MySQL string connection
I need some advice on a little project im doing. I have a database
Alright, I need some advice and best practices from some Rails people. I'm fairly
Please advice the best way to organize editing my Restaurant entity in MVC3. I
I need edit my Images before they import to the app but after editing
I need to edit format for JFormatedTextField in a Java program. NetBeans are helping

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.