Search code examples
regexnotepad++regexp-replace

Find and Replace Text with RegEx in Notepad++


Does anyone have an idea how I can achieve the following with Notepad++.

For example, I have the following text:

 { 1000000003;1;Column; ;
               DataSource=Search Name }

    { 10000004;1;Column; ;
               DataSource=Name 2 }

Is it possible to put the value that follows DataSource= in the line above?

The value is to be set after Column;.

The result should look like this:

{ 1000000003;1;Column;Search Name ;
               DataSource=Search Name }

    { 10000004;1;Column;Name 2 ;
               DataSource=Name 2 }

I have already created the following RegEx:

(;Column;)|(?<=DataSource=)\w+\s+\w+\.?)

With this I find what I need, but I did not manage to get the desired result with it.

Is this possible at all with RegEx or is there a plugin that can do this?


Solution

  • You can search using this regex with 3 capture groups:

    (Column\s*;)\s*(;\s*DataSource=([^}]+))
    

    and replace with:

    $1$3$2
    

    RegEx Demo