Sequence number 1, 2, 3... Change to adding a 0
-
Hi…
I have a notepad++ document with my questions in this format:
1-
2-
3-
4-And I want now them to be:
01-
02-
03-
04-The problem is there are not consecutive in the document… I mean…
1- How are you?
A) Fine
B) Fine
C) Fine
D) Fine2- How old are you?
A) 21
B) 21
C) 21
D) 21So i want to know if there is a method to secuence them like 01, 02, 03… despite they are not one below the other.
There are 325 questions.
Thanks.
-
In one step, with just Notepad++? No. Notepad++ cannot natively handle mathematical replacements, as explained in this FAQ (which contains some of the workarounds mentioned below).
If you allow for more than one step, or if you are willing to install a plugin, then yes.
Until recently, I would have recommended a multi-step process, similar to:
- replace all newlines that don’t come before #- with a different character that you don’t use in your document, like a smiley face (
\R(?!\d+-)
⇒☺
) - delete all the numbers before the - at the beginning of each combined line (
^\d+(?=-)
⇒ empty) - Use a column selection then Column Editor (Edit > Column Editor or
Alt+C
) to insert numbers starting at 1 with leading zeroes - change the different-character back into newline sequence (
☺
⇒\r\n
for Windows EOL)
But now that there are a couple of plugins that more easily handle mathy replacements, I’d suggest using one of those.
For the Columns++ plugin, I am pretty sure that something like the following (derived from this FAQ section would work with Columns++ (and the author @Coises will correct me if I’m wrong):
- Using the plugin’s search/replace (not Notepad++ search/replace)
FIND =^\d+-
REPLACE =(?=3:match)-
- where the
3
in that replacement means it will be three digits (001 - 325) - and the
match
in that replacement means
- where the
And in the MultiReplace plugin, I think you would need to use the
CNT
variable in its search/replace feature.----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
- replace all newlines that don’t come before #- with a different character that you don’t use in your document, like a smiley face (
-
Thnak you and thanks too for the FAQ`s!
-
Your title and example suggests that the question numbers are already correct, you just want to add a zero before them, and you say you have 325 questions; so I wonder, do you want:
01- 02- ... 09- 010- 011- ... 099- 0100- 0101- ... 0325-
which is what your question, taken precisely, says? Or:
001- 002- ... 009- 010- 011- ... 099- 100- 101- ... 325-
which is what I think @PeterJones assumed you meant?
Also, are the numbers themselves already correct (just missing the leading zeros), or do you need to renumber, too?
If all you wanted was to add one zero before every question number, and the pattern follows your example that all question lines, and only question lines, start with a number, then all you need is:
From the menu, select Search | Replace; in the dialog, set:
Find what :
^(\d)
Replace with:0$1
Search Mode : Regular expressionand use the Replace All button.
-
This post is deleted!