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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:56:00+00:00 2026-06-08T05:56:00+00:00

For example, if I have $asd[‘word_123’] and I wanted to replace it with $this->line(‘word_123’)

  • 0

For example, if I have $asd['word_123'] and I wanted to replace it with $this->line('word_123'), keeping the ‘word_123’. How could I do that?

By using this:

%s/asd\[\'.*\'\]/this->line('.*')/g

I will not be able to keep the wording in between. Please enlighten me.

  • 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-08T05:56:02+00:00Added an answer on June 8, 2026 at 5:56 am

    Using regex, you could do something like :%s/\$asd\['\([^']*\)'\]/$this->line('\1')/g

    Step by step:

    %s – substitute on the whole file

    \$asd\[' – match “$asd[‘”. Notice the $ and [ need to be escaped since these have special meaning in regex.

    \([^']*\) – the \( \) can be used to select what’s called an “atom” so that you can use it in the replacement. The [^'] means anything that is not a ', and * means match 0 or more of them.

    '\] – finishes our match.

    $this->line('\1') – replaces with what we want, and \1 replaces with our matched atom from before.

    g – do this for multiple matches on each line.

    Alternative (macro)

    Instead of regex you could also use a macro. For example,

    qq/\$asd<Enter>ct'$this->line(<Esc>f]r)q
    

    then @q as many times as you need. You can also @@ after you’ve used @q once, or you can 80@q if you want to use it 80 times.

    Alternative (:norm)

    In some cases, using :norm may be the best option. For example, if you have a short block of code and you’re matching a unique character or position. If you know that “$” only appears in “$asd” for a particular block of code you could visually select it and

    :norm $T$ct'this->line(<C-v><Esc>f]r)<Enter>
    

    For a discourse on using :norm more effectively, read :help :norm and this reddit post.

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

Sidebar

Related Questions

I am using Simple.Data and have been trying to find an example that will
I have this line that I want to use sed on: --> ASD =
I have, for example, this string: asd? asdfasdfsdf <description>&lt;div? style=&quot;color:000000;font-family:Arial, Helvetica, ?sans-serif;font-size:12px;font-size:12px;width:555px;&quot;&gt;Bohus Malm?t;/a&gt;</description> blah
Example: I have an class that inherits from UIImageView. An object creates an instance
Example: I have a selector like this, which I give to another method as
Example: I have a method -myFooBarMethod:withFoo:bar:moreFoo: and inside the implementation of that method I
An example, I have a string that contains let's say: function main { //
I have a radio group that allows the user (using jQuery events) to deselect
For example I have a table like this: product | quantity | something -------------------------------
I have a procedure that return daily report between a time example (CreateDate BETWEEN

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.