Replace a specific char with the begining of the line
Hi friends, I hope you can help me please
i have a text file formatted like this :
What I want to do is to insert the Cell number between the double +
I tried with regex but didn’t find out how to solve this.
Thank you for your help
- FIND =
- REPLACE =
- SEARCH MODE = Regular Expression
- REPLACE ALL
Will replace the first
++on each line with the cell value. Clicking Replace All N times (where N is the maximum number of
++on any of the thousands of lines in your file – or just stop clicking when the Replace dialog says “0 occurrences were replaced in entire file”) will propagate it to the very end.
^= start match at beginning of line
(\w+)= grab as many word characters (A-Z, 0-9, _) and store in group#1
.*?= move forward on the line until whatever comes next in the regex is matched (this is a way to skip 0 or more characters, when you don’t know how many characters it will be)
\K= this is a fancy thing that says “do all the matching before this symbol, but don’t include the text before this when i do a replacement later” – or, essentially, “keep (hence the
\K) the text that comes before this”
\+\+= match two literal
+signs (+ is special to regex, so need a \ before it)
+$1+=> replace just the two + from the match with a single + then the contents of group 1 then a single + .
(Sorry that you might have to hit Replace All multiple times. it might be possible to do with a very complicated single regular expression even if we cannot guarantee how many
++there are beforehand, but it’s much easier to explain one where you just replace one
++per line at a time. With a file with 1000 or 10000 lines, if you only have 10
++per line, so it grows with the number of
++not with the number of lines, so there is at least that. And honestly, if you had more than 10 in a given row, the regex would be too complicated to type and use, so hitting 10 Replace All seems doable. If you might have 100
++on a single line, then I suggest recording the replacement I showed as a macro, then use Macro > Run a Macro Multiple Times to specify that you want to run the replacement 100 times without having to do 100 clicks.)
- FIND =
Peter Jones you saved my day !!
Thank you very much <3