Add Increment Number (part 2)
-
So, I have this:
bebe-55
bebe-55
bebe-55I made a regex so to add number 1-3, before each line:
1-bebe-55
2-bebe-55
3-bebe-55Solution very good, but…:
FIND:
\A(bebe-55)(?:\R\1){2}\z
REPLACE:1-\1\n2-\1\n3-\1Or this:
FIND:
\A(.*)\R(.*)\R(.*)\R?\Z
REPLACE:1-$1\r\n2-$2\r\n3-$3But if I have 2000 lines, the replace should contain several hundred pages. I need another idea.
My only problem is that the Replace expression is too long. I want a shorter replace.
I also try this shorter:
FIND:
^(bebe-55)$
REPLACE:1-\1(?{1}\2)$2But this doesn’t work.
I need a shorter incremental regex, not column editor
Also I
-
add number 1-16, before each line:
1-bebe-55
2-bebe-55
3-bebe-55Notepad++'s existing “Column Editor” can do this already.
I believe the default keycombo is Alt+c (or you can find it on the Edit menu). -
@Alan-Kilborn I need a regex, not column editor, not python.
-
I need a regex, not column editor, not python.
If you have multiple files, it is understandable to exclude column editor, as that’s not practical. But you are choosing to exclude PythonScript: there is a difference. You have access to the plugin, and you know how to use it. So you do not need a regex, you want a regex, which are two different things.
Notepad++'s built-in regex doesn’t do auto-increment, and your previous topic with the edge cases just pointed that out to you (you ended up doing a weird duplicate and edge-case to get a pseudo-‘count’). For this task, you would need to use a plugin – either PythonScript (which you are artificially rejecting), or one of the fancier search plugins that have enabled custom “numbering” syntax – like MultiReplace or Columns++ (or presumably Search++ – I assume @Coises included all the math extras when he ported the searching from Columns++ to Search++)
The Math FAQ already explains how to do counting-like actions in PythonScript and in MultiReplace and in Columns++ (and I assume the Search++ syntax would be the same). There is no reason for us to re-iterate what’s already in the FAQ.
-
Hi, @Neculai-i.-fantanaru and All,
For this purpose, you should study the
Columns++documentation of @coises, below :https://coises.github.io/ColumnsPlusPlus/help.htm#formulas
or with the
MultiReplaceplugin of @thomas-knoefel, from these two links below :https://github.com/daddel80/notepadpp-multireplace/blob/main/FORMULA-SUPPORT.md#lua-reference
https://github.com/daddel80/notepadpp-multireplace/blob/main/FORMULA-SUPPORT.md#exprtk-reference
As you can see, it should be possible with some special regexes to achieve your goal !
Best Regards,
guy038
-
PeterJones said:
I assume the Search++ syntax would be the same
Per the Search++ announcement, it can do the numeric calculations that were first developed for Columns++.
I should update the FAQ soon…
-
PeterJones said:
I assume the Search++ syntax would be the same
Per the Search++ announcement, it can do the numeric calculations that were first developed for Columns++.
I should update the FAQ soon…
I recommend waiting on that update. Search++ is not “production ready” yet. People shouldn’t be using it at present unless they want to be beta testers. Once I reach a 1.0 release I’ll make a serious effort to avoid changing things that people would expect to stay the same, but right now, anything could be changed at any time.
Numeric expressions in Search++ do not have quite all the features of numeric expressions in Columns++; in particular, the history options (using the values captured or computed in a previous match) aren’t supported in Search++, and the exprtk return statement isn’t supported.
However, I think all the features directly cited in the Math FAQ are included. The
reg(1)syntax still works, but in Search++ you can use$1as well. However, a quirk is that since Search++ doesn’t have the persistent Decimal separator is comma option of Columns++, it’s necessary to useregc(1)or$$1for European-style numbers with periods and/or commas.Finally, Columns++ can only work on the active document. Search++ has a Find in Files option, but Replace in Files has not yet been implemented. So if your guess was correct and @neculai-i.-fantanaru wants a regular expression because it must be applied to many files at once, @thomas-knoefel’s MultiReplace is the best choice among presently-existing options.
Oh, and MultiReplace has recently added an option to use exprtk formulas as an alternative to its Lua syntax.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login