1

i want replace after "string"

stringreplacefield character by character

for generate

 stringstringeplacefield

after the first replace

  stringstringstringplacefield

after the second replace

 stringstringstringstringlacefield

after third replace

 stringstringstringstringstringacefield

using a not matched group
in notepad++

I have tried this several days

please help me

jhonny625
  • 266
  • 2
  • 14

1 Answers1

0

Description

(((?:string)+)(?!string).([^\n\r]*?)(field))\Z

Replace With: $1\n$2string$3$4

Regular expression visualization

From Notepad ++

From Notepad++, note that you should be using notpad++ version 6.1 or later as there were problems with regular expressions in an older version that have been solved now.

  1. press the ctrlh to enter the find and replace mode

  2. Select the Regular Expression option

  3. In the "Find what" field enter (((?:string)+)(?!string).([^\n\r]*?)(field))\Z

  4. in the "Replace with" field enter $1\n$2string$3$4

  5. Click Replace all. Each time you click replace all, a new character will be eaten, and a new line will be inserted.

Example

Regex Demo

https://regex101.com/r/jK6jF7/1

Sample text

stringreplacefield

After Replacement

1st time
   stringreplacefield
   stringstringeplacefield

2nd time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield

3rd time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield

4th time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield
   stringstringstringstringstringacefield

5th time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield
   stringstringstringstringstringacefield
   stringstringstringstringstringstringcefield

6th time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield
   stringstringstringstringstringacefield
   stringstringstringstringstringstringcefield
   stringstringstringstringstringstringstringefield

7th time
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield
   stringstringstringstringstringacefield
   stringstringstringstringstringstringcefield
   stringstringstringstringstringstringstringefield
   stringstringstringstringstringstringstringstringfield

8th time since there are no more characters between "string" and field, then no more replacements are made
   stringreplacefield
   stringstringeplacefield
   stringstringstringplacefield
   stringstringstringstringlacefield
   stringstringstringstringstringacefield
   stringstringstringstringstringstringcefield
   stringstringstringstringstringstringstringefield
   stringstringstringstringstringstringstringstringfield

Explanation

NODE                     EXPLANATION
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    (                        group and capture to \2:
----------------------------------------------------------------------
      (?:                      group, but do not capture (1 or more
                               times (matching the most amount
                               possible)):
----------------------------------------------------------------------
        string                   'string'
----------------------------------------------------------------------
      )+                       end of grouping
----------------------------------------------------------------------
    )                        end of \2
----------------------------------------------------------------------
    (?!                      look ahead to see if there is not:
----------------------------------------------------------------------
      string                   'string'
----------------------------------------------------------------------
    )                        end of look-ahead
----------------------------------------------------------------------
    .                        any character except \n
----------------------------------------------------------------------
    (                        group and capture to \3:
----------------------------------------------------------------------
      [^\n\r]*?                any character except: '\n' (newline),
                               '\r' (carriage return) (0 or more
                               times (matching the least amount
                               possible))
----------------------------------------------------------------------
    )                        end of \3
----------------------------------------------------------------------
    (                        group and capture to \4:
----------------------------------------------------------------------
      field                    'field'
----------------------------------------------------------------------
    )                        end of \4
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  \Z                       before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
Ro Yo Mi
  • 14,790
  • 5
  • 35
  • 43
  • hi goog answer but i want this in one line not multiple lines and; not using "string" using a variable for replace charcater for string redirecting – jhonny625 Jun 19 '16 at 18:17
  • please if possible see my other question – jhonny625 Jun 19 '16 at 18:18
  • http://stackoverflow.com/questions/37902418/replace-after-word-character-by-character-in-notepad and resolve it – jhonny625 Jun 19 '16 at 18:18
  • for example i see other example of you redirect a variable \s(?=.{18}(.)) , i want use any character after string and replace by string as not matching group using a subtitution $1 – jhonny625 Jun 19 '16 at 18:29
  • 1
    good answer, I think I have no problems I could solve my doubt thanks to your other answer, very thankyou – jhonny625 Jun 19 '16 at 19:55