Regex: Insert new line at the beginning of file
-
maybe someone will need this Regex:
Select only the first line of the text-file
^\A(.*)$Insert any word in the beginning of file:
Search^\A(.*)$
Replace withWord $1Select the last line of the text-file
^(.*)$\zinsert word at the end of file
Search^(.*)$\z
Replace with$1 WordAdd a new empty line at the beginning of file:
^\A(.*)$
Replace cu\r \1Add a new empty line after the first line:
Search^\A(.*)$
Replace cu\1 \r(after \r leave an empty space) -
And to Insert a new line at the end of file
Search^(.*)$\z
Replace by:\1 \r -
I think I fail to see why these are useful regexes in a Notepad++ context. For example, if I want to select the first line in a file, I just do it. If I want to insert a word at beginning of file, I just do it. And so on. Regexes definitely have their uses, but it seems maybe that you are just playing around and learning about this topic.
-
I wonder myself why, until I had to modify 2000 html files, namely to add a particular php script at the beginning at each html file.
It helps me a lot !
-
I see. Perhaps in these situations one should look into a text-processing language, e.g. Python, Perl, AWK, sed, etc. If you do so, you will see the benefits of these languages. This has been pointed out many times before on this forum. It of course can be done in Notepad++, but it is good to have many tools in the toolbox so that every problem you have to solve doesn’t start looking like a nail.
-
Notepad with Regex is much easy to use, for me, which I am not a programmer. And, I believe, there are many people like me… Not everyone is a programmer.
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