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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:21:17+00:00 2026-05-25T10:21:17+00:00

There is a search and replace operation I am trying to do using backreferencing

  • 0

There is a search and replace operation I am trying to do using backreferencing and regular expressions in vim. Interestingly, it will only recognize the pattern if I do a pure search, but if I do a search and replace it gives me an E486: pattern not found error.

I have a bunch of function calls of the form:

function( Nullable< double >(1.1), map[FOO] );

Where FOO is some different variable name on each line. I want to turn it into

function( othermap[ FOO ], map[FOO] );

If I try

:%s/Null.*\(map[\)\(.*\)\]/othermap[ \2 \], \1\2\]/g

It gives me the “Pattern not found error.” Even

:%s/Null.*\(map[\)\(.*\)\]//g 

will not work because it’s just not recognizing the pattern. But if I try the following command with the exact same search regex:

/Null.*\(map[\)\(.*\)\]

It highlights correctly. Following which, I can do %s//othermap[ \2 ], \1\2] to do my replacement. So I was able to do my replacement after all, but I can’t for the life of me understand why the pattern would be recognized in one case and not in the other.

  • 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-25T10:21:18+00:00Added an answer on May 25, 2026 at 10:21 am

    I can reproduce the result using copy’n’paste from your question to my vim session. The detailed message I get, though, is:

    E486: Pattern not found: Null.*\(map[\)\(.*\)\]/othermap[ \2 \], \1\2\]/g
    

    Note that it has lost the s/ at the start.

    However, looking rather carefully at this, the trouble is an unescaped [:

    s/Null.*\(map[\)\(.*\)\]/othermap[ \2 \], \1\2\]/g
                 ^
                 |-- here; you need \[ to match the literal
    

    I don’t use the % notation; I would automatically write:

    :g/Null.*\(map\[\(.*\)\]\)/s//othermap[\2], \1/g
    

    This has slightly different capturing. There was also no need to use the backslash in \] in the replacement string.

    However, this command also works for me:

    :%s/Null.*\(map\[\(.*\)\]\)/othermap[\2], \1/g
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply a search and replace regular expression pattern that work only
Is there some sort of profiling tool available? View source and search/replace?
Is there a way to search for multiple strings simultaneously in Vim? I recall
If there are extensive modifications made to search.aspx in SPS 2003, will they get
I require a regular expression for the Visual Studio Search and Replace functionality, as
Is there a way to do a project wide search and replace in netbeans?
There is a request to make the SO search default to an AND style
There are several plugin options for building a search engine into your Ruby on
Is there a tool to automatically search through my site and test all the
Is there any way to keep search engines from indexing text ads? These are

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.