2

I am trying to edit a .srt file, and I am stuck on a specific task. I am sure there may be an easier way, but after searching for a couple hours, I am unable to find anything that helps me. I am trying to select all occurrences of the string "1" and then use the column editor to increment those occurrences by 1.

The first picture here shows the main issue in my .srt file. I am wanting to Select, not highlight all of the values that are currently highlighted in green. The find and replace box doesn't seem to help any because I need to do my increment operation using the column editor on the selected string. I have also tried the mark feature and that didn't do any good either.
enter image description here

Once I have them selected I can do These operations. enter image description here

enter image description here

enter image description here

I know that I can hold the ctrl key down and manually select the lines that I need to edit, but that would take forever. It is kind of frustrating knowing that the text I need to select is already highlighted in green, but not selected. I am only a novice user when it comes to Notepad++ so I don't know all the features. Any help would be much appreciated. Thanks.

trenten
  • 99
  • 1
  • 2
  • 13
  • IMHO the simplest way is to write a script in your favorite scripting language. – Toto Jun 14 '16 at 10:35
  • Lol I know very very basic python and java. I can't fathom why there isn't a simple feature such as search and select. Like the values I need to select are already highlighted in green for crying out loud. – trenten Jun 14 '16 at 14:34
  • If someone could explain how difficult it is to write the code for it do to something as simple as selecting. I have no idea what type of programming commands I would have to use or even how to implement the code into Notepad++. Are you sure there isn't a simple way to select specific text? – trenten Jun 14 '16 at 15:39
  • The difficulty is not the selection but the replacement. To select all lines that have only `1` in them: `menu Search > Mark...`, type `^1$` in the search box, check `Mark the lines` then click on `Find All`. I'm not sure of all these therms because I haven't an english version of Npp. – Toto Jun 14 '16 at 16:21
  • I just tried that, and the mark feature doesn't seem to actually select what I need. It feels like it just highlights. If I manually select the lines with one and do the column editor operation, it works. Here's a picture of what i tried, I used my own website to host the picture to keep the quality. http://www.pcrepairforums.com/attachment.php?aid=36 . In the question above, you can see that if I manually select the lines with the number 1 and perform that column edit operation it works as I need it to, but if I try it with the mark feature it doesn't seem to actually select the text. – trenten Jun 14 '16 at 17:44
  • I think I could see this going two ways. Either find a way to select all lines with the number 1, or find a way to select multiple lines that are immediately below a blank line. then I could complete my increment number operation. – trenten Jun 14 '16 at 18:09

1 Answers1

1

This is not possible to select that text easily. However, if you have PythonScript plug-in, this is easily done with Python script like

counter = -1

def increment_whole_line_number(match):
    global counter
    counter += 1
    return str(int(match.group())+counter)

editor.rereplace(r'(?m)^\d+$', increment_whole_line_number)

The (?m)^\d+$ regex matches a whole line that consists of digits only (1 or more digits).

Here are the instructions on how to install the working PythonScript version (as the built-in does not work for me for some reason).

Here is my test:

enter image description here

Community
  • 1
  • 1
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • To make the regex a bit more precise for your scenario, you may use `(?m)^\d+(?=\r?\n\d{2}:\d{2}:\d{2},\d{3} -->)` – Wiktor Stribiżew Jun 16 '16 at 08:25
  • 1
    Thanks, I have to go to the dentist, but I will be sure to give this a try this evening. – trenten Jun 16 '16 at 15:14
  • 1
    I had a little time, and it worked first try. Thanks so much. Learning new things everyday. Now I'll study the script and learn how it applies to notepad++ so maybe I can build my own. – trenten Jun 16 '16 at 15:48