How to put parts of code...
-
Hello,
I have such question. I have a list of urls, like that:
http://example.com
http://example.com
http://example.comAnd how to make this (instead ABC there is part of code, many lines):
http://example.com
ABC
http://example.com
ABC
http://example.com -
If
ABC
is the same every time, then
FIND =http://example.com(\R)
REPLACE =${0}ABC${1}
MODE = regular expressionThe
${0}
includes the original matched line in the file in the replacement
The${1}
adds a newline afterABC
-
This post is deleted! -
@rafal-jonca-1 said in How to put parts of code...:
Funny, it works very nicely on http://example.com, but not on my urls. Probably because how the urls are constructed. I paste an example of my http:
Nobody in their right mind is going to try to sort that out.
You need to read and follow the FAQ entry for such requests.
See HERE. -
This post is deleted! -
@rafal-jonca-1 said in How to put parts of code...:
So I will try to make it clearer.
OMG can’t you get that data into black boxes so that this site won’t muck with it? I linked to instructions for doing so…
When you post it should appear like this:
COPYING -- Describes the terms under which Notepad++ is distributed. A copy of the GNU GPL is appended to this file. IMPORTANT NOTEPAD++ LICENSE TERMS Copyright (C)2021 Don HO <don.h@free.fr>. This program is free software; you may redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; Version 3 with the clarifications and exceptions described below. This guarantees your right to use, modify, and redistribute this software under certain conditions. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ****************************************************************** GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
-
@rafal-jonca-1 said in How to put parts of code...:
Funny, it works very nicely on http://example.com, but not on my urls
Your example data implied that it was the same URL every time, by using the same url every time. If you want good answers, ask a good question.
If you really have data that is varying, like
http://site1.com http://a.different.site.com http://www.site3.com/blah/a+b+c https://a.modern.site/yada?holy+cow+this+wasnt+hard+to+craft
then show us data that varies – it’s really not hard, even when crafty dummy examples, to make it reasonably reflect your actual data without needing to be your actual data (notice how easily I crafted data that showed there was variation) – so that you aren’t forcing us to make assumptions about your data.
Assuming that each URL line always starts with
http://
orhttps://
(note, that’s still an assumption; according to even your recent, poorly-presented example data, it all still showshttp://
, but I am going to err on the side of more caution this time):- FIND =
(?-s)^https?://.*(\R)(?=\Z|^http)
- REPLACE =
${0}ABC${1}
This looks for any line that starts with
http://
orhttps://
and puts a lineABC
after it.If this still doesn’t work for you, then use the template that Alan already linked you to, and provide BEFORE and AFTER that accurately represents what you want.
(Crafting regex highly depends on the data you have, so misrepresenting the data will cause a higher likelihood of the regex not working.)----
Useful References
- FIND =
-
It works very well, Peter. Thank you.