Search code examples
regexnotepad++

How would I duplicate a line and change a piece of text inside of the duplicate line?


I have recently ran into a problem that I am searching automation for using RegEx using Notepad++. I have some very limited experience with RegEx in N++, however I cannot figure out how to do the following:

I have the following line:

["Cost"] = 100,

And I want to achieve the following:

["Cost"] = 0,
["CostNew"] = 100,

Since I have many lines of "Cost" as portrayed above with varying values (I'm just using 100 as an example) I would need an automation for this process.

I am aware that you can create a new line by using "\n", but that is as far as my knowledge extends.

Is there a way of doing this with a RegEx expression? Or is it perhaps done better through multiple RegEx expressions?

Thank you in advance for reading my question!


Solution

  • Try this with unticked Match-Case

    Find what: (\["cos)([^,])
    Replace with: $1t"] = 0,\n$1$2new