Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line's number using regex in Notepad++?

Is it possible to get the line's number using regex in Notepad++;

what I want to do, is replacing:

line1
line2
line3
etc..

with

1-line1
2-line2
3-line3
etc..
like image 308
N. Chamaa Avatar asked Jan 31 '13 22:01

N. Chamaa


People also ask

Can I use RegEx in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

Can we type numbers in notepad?

If you're using the numeric keypad, you have to turn the "num lock" feature on, but if you use the number keys across the top of the keyboard, all the numbers as well as the symbols above them work just fine for me. As an alternative to Notepad, you could try Wordpad which is much better for word processing anyway.


2 Answers

Notepad++ can do that by using the TextFX plugin. Select the lines and then select TextFX->TextFX Tools->Insert Line Numbers from the menu bar.

This will add line-numbers padded to 8 places with leading zeros. To get them in the form described in your question, you can use a regex-replace with these values:

search for: ^0+([0-9]+)\s

replace with: line\1-

like image 75
Philipp Avatar answered Oct 08 '22 04:10

Philipp


Older question, but I had this question myself today and found another answer than those presented already.

Column Editor (Alt + C) provides a way to insert numbering. Options exist to choose the starting number, interval, and how often each number should be repeated. Place the cursor on the first position of the first line and increment by one to mimic the actual line numbers.

like image 25
Jim Avatar answered Oct 08 '22 04:10

Jim