3

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?

user3644868
  • 127
  • 1
  • 1
  • 6

2 Answers2

1

Yes you can do it using Notepad++.

Use search and replace with the following search pattern:

({.*?;)( )?(;.*?DataSource=)(.*?)( })

and replace with:

$1$4$3$4$5

The logic behind it is matching all of your string with capture groups, before and after the part you want to replace, then re-building it with the same capture groups - only replacing the specific capture group of the replace point which is the second group ( )? with the destination value group which is the fourth group (.*?)

Here is a working example in regex101

And a screenshot from Notepad++:

enter image description here

Alon Adler
  • 3,984
  • 4
  • 32
  • 44
1

You can search using this regex with 3 capture groups:

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

and replace with:

$1$3$2

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Can you please help me with this again? `Column;Phone (No.)` I would now like to remove everything after ;Column; that does not correspond to [A-z0-9]. I have tried this regex, but it does not work. `(;Column;)*([A-z0-9]+)` Substitution $1$2 https://regex101.com/r/LxhQ8g/1 What am I doing wrong? – user3644868 Mar 18 '23 at 09:38
  • So you want `Column;Phone (No.)` to become `Column;Phone No` or what? – anubhava Mar 18 '23 at 09:56
  • Exactly. Only without spaces, i.e. `Column;PhoneNo` – user3644868 Mar 18 '23 at 16:53
  • Check this demo: https://regex101.com/r/LxhQ8g/2 – anubhava Mar 18 '23 at 18:06
  • Can this also be done as a replace variant? So I would have to replace `Column;Phone (No.)` with `Column;PhoneNo` – user3644868 Mar 18 '23 at 21:08
  • No the one that I posted above is right approach that doesn’t assume any format of input data – anubhava Mar 19 '23 at 03:22
  • Can you tell me what the solution would be if there were input data? – user3644868 Mar 19 '23 at 09:59
  • Sorry I am confused now. I have already given solution yesterday. May be you can post a new question to give more clarity of your problem so that we can give you best solution. – anubhava Mar 19 '23 at 10:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252602/discussion-between-user3644868-and-anubhava). – user3644868 Mar 19 '23 at 11:14