Kolla
Kolla

Reputation: 75

Regex search and replace with grouping

I have a file with hundreds of lines looking like the ones below. My regex skills were not enough to get the job done. I'm trying to do this replace in Notepad++ with the search and replace using regex, have also tried (and failed) in vim.

This is my regex

public string (^[A-Z]*[\S]) { get; set }

So I want to make the first line look like this

Foretag public string Foretag { get; set; }

and all the lines following it matching my search term which is Type="string"

Foretag Type="string"
DagboksDatum Type="DateTime"  
Byggdag Type="int"  
PaborjadeArbeten Type="string"  
FardigaArbeten Type="string"  

Upvotes: 0

Views: 265

Answers (2)

romainl
romainl

Reputation: 196546

In Vim:

:%s/\(\w*\).*string.*/\1 public string \1 { get; set }

Upvotes: 5

AdamL
AdamL

Reputation: 13151

You would do it like this in Npp:

find what:

^(\w+) Type="(\w+)"

replace with:

\1 public \2 \1 { get; set; }

Upvotes: 3

Related Questions