Notepad++ Regular Expression for Selected Group Line Number Before The Lines Group Start
-
I am using this below Regular Expression in notepad++.
(?-s)^(.+)\R(.+)\R(.+)\R
— i am wanted to get the the out put like for example if i have multiple lines; like below:
358 293 866 511 58 767 562 644 163 569 414 305 973 16 692 128 353 1000 870 58 535 866
Now I am wanted to get the OutPut like this;
@@1@@358 293 866 @@2@@511 58 767 @@3@@562 644 163 @@4@@569 414 305 @@5@@973 16 692 @@6@@128 353 1000 @@7@@870 etc
Like i am wanted to add the number in @@i@@ of the group that it select.
Looking forward for some working solution. Best Regards, Thanks
-
As far as I can see, this can’t be done natively in Notepad++ —at least it would not be an easy task, maybe a really complex regex could accomplish it—, but it is doable by extending Notepad++ capabilities via scripting, specifically, by means of the Python plugin.
Let me show you how can it be done:
Quick instructions:
- Install the Python plugin.
- Copy Ekopalypse’s script from here
https://community.notepad-plus-plus.org/post/51832
and save it in the “Scripts” directory (access it from the mentioned plugin). Say you named it “Select all same words”. - Open the Find dialog box and apply the following regex to your list of numbers:
Search: (?-s)^.+\R.+\R.+\R Replace: @@#@@$0
- Select the sharp
#
and execute the Python script “Select…”. All the sharp characters will be selected. - Open the Column Editor and set 1 as initial number and also 1 as the increment.
- Press OK and all the
#
will be replaced with successive integers, as you wanted.
Hope this makes sense :)
-
If opening it up to programming via Pythonscript, it might as well be an entirely P.S. solution (which I won’t publish here).
But, the way you did it keeps the programming part generic when needs like this come up: the P.S. is kept the same, and only the search/replace done in N++ is different – this makes it easier for those that are “afraid” of programming.
It also emphasizes that being able to do an automatic multiselection is an important operation (that maybe should have better support in native N++).
-
I agree with all your points — try to use as much as possible the native features of Notepad++, make things as easier as possible so everyone can understand, learn, and eventually apply them, and a better (automatic, as you said) implementation of multiselection, which could open a wide array of powerful operations.
Hoping that future development will take care of this feature.
Have fun :)
-
Hi, @garbage-gold, @astrosofista, @alan-kilborn and All,
Again, I would use a combination of regex S/R and the column Editor feature !
So, from the input text, below :
358 293 866 511 58 767 562 644 163 569 414 305 973 16 692 128 353 1000 870 58 535
Using the following regex S/R :
SEARCH
(?-s)^(.+)\R(.+)\R(.+)
REPLACE
@@@@\1\t\2\t\3
we get the text, with words separated by a
TAB
char :@@@@358 293 866 @@@@511 58 767 @@@@562 644 163 @@@@569 414 305 @@@@973 16 692 @@@@128 353 1000 @@@@870 58 535
Now, place the caret after the two first
@
characters of the first lineAnd using the column editor (
Alt + C
) and inserting a list of numbers, beginning with1
, we obtain :@@1@@358 293 866 @@2@@511 58 767 @@3@@562 644 163 @@4@@569 414 305 @@5@@973 16 692 @@6@@128 353 1000 @@7@@870 58 535
Finally, using the simple S/R :
-
SEARCH
\t
-
REPLACE
\r\n
( or\n
only for Unix files )
You’ll have your expected text :
@@1@@358 293 866 @@2@@511 58 767 @@3@@562 644 163 @@4@@569 414 305 @@5@@973 16 692 @@6@@128 353 1000 @@7@@870 58 535
Best Regards,
guy038
-