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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:52:39+00:00 2026-06-04T19:52:39+00:00

Given the following, i’d like to comment lines starting with 1 or 2 or

  • 0

Given the following, i’d like to comment lines starting with 1 or 2 or 3

Some text
1 101 12
1 102 13
2 200 2
// Some comments inside
2 202 4
2 201 7
3 300 0
3 301 7
Some other text

The following regex (seems to) look(s) right, and yet it does not work ..

%s/^([123])(.+)/#\1\2/g

The same regex matches when used by egrep

egrep '^([123])(.+)' file_name

Please help me understand why this search and replace is failing in VI

  • 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-04T19:52:40+00:00Added an answer on June 4, 2026 at 7:52 pm

    You need to escape the characters: ()+. So you could do %s/^\([123]\)\(.\+\)/#\1\2/g, but it seems easier to do: :g/^[123]/s/^/#

    Note that vi does have various options for changing the meaning of symbols in patterns (help magic). In particular, you could use ‘very magic’ and do: :%s/\v^([123].+)/#\1/g (note that the g flag is completely redundant here!)

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

Sidebar

Related Questions

Given the following code <div class=container> <p>Some Text</p> <p><img src=image.jpg><p> <p>More Text</p> </div> CSS
I should convert some code from VB to C#. Given following lines of VB
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given the following text: |Description=This is the start of the ... ... <strong>description</strong> of
Given the following string http://thedude.com/05/simons-cat-and-frog-100x100.jpg I would like to use substr or trim (or
I need some help with modeling in Cognos Framework Manager 8.4. Given following schema
given the following text file: Find all HeaderText=, Subfolders, Find Results 1, Entire Solution
Given following snippet in a view: <style type=text/css> input[type=text] { width: <%: Model.CmsConfiguration.cms_form_width %>px;
Given the following input string: (?i:\bsys\.user_catalog\b) Stored into sqlite TEXT field. When retrieved with
given the following 2 lines of strings, for example : May 22 00:46:38.340 prod-lab03c-rd1

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.