0

Is it possible to use the value of a regex in the "FIND" part of a find/replace in Notepad++ ?

Here's what i have :

FIND: ^.{105}.*(.)
REPLACE: \r\n

the value to replace is the 106th character in my file. let's say it's an ~

now the find/replace should find & replace all occurrence of ~ and replace all of them by '\r\n' (the ~ represent the end of line character)

It doesn't work, it replace the whole string instead of the 106th char and only replace once instead of multiple time on the file.

The whole purpose of this is to have this set on a hotkeyed macro so it can be done quickly and often.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327
Jim Cusler
  • 23
  • 3
  • input text : [ 123456789[..]104~line2~line3randomtext~line4sometext ] The expected result is: for this line of text : The regex should gets the 105th char ( ~ in this case ) then find and replace all of the char returned by the regex (~ from example) in the text by constant character /r So basically, here the variable is the text in "find" part of the find/replace and the constant is the "replace by" text (\r). TEXT AFTER MODIFICATION : 123456789[..]104/rline2/rline3randomtext/rline4sometext – Jim Cusler May 18 '16 at 14:39

2 Answers2

2

I think you want something along these lines:

Find: ^(.{105}.) Replace: \1\r\n

You need to wrap the thing in a capture group otherwise your ^ will force it to only match the beginning of the line. You'll also need to include the first capture group as part of the replacement string so it won't nuke the entire matching.

  • This break a line in multiple line of 105 character long. What it should do is for this line : [ 123456789[..]104~line2~line3randomtext~line4 ] the regex gets thr 105th char (~ in this case) then find and replace all ~ in the text by (/r) so in this case the variable is the text to find. the replacing text is hardcoded (\r). – Jim Cusler May 18 '16 at 14:29
  • This break a line in multiple lines of 105 characters. The expected result is: for this line of text : [ 123456789[..]104~line2~line3randomtext~line4sometext ] Now the regex should gets the 105th char ( ~ in this case ) then find and replace all of the previous char (~ from example) in the text by constant char (/r) Here the variable is the text to find. The constant is the replacing text (\r). – Jim Cusler May 18 '16 at 14:36
0

You could do:

Find what: ^(.{105}).
Replace with: $1\r\n

Make sure you have checked Regular expression BUT NOT dot matches newline

then click on Replace all

This will capture in group 1 the first 105 characters in each line.

Toto
  • 89,455
  • 62
  • 89
  • 125