Select every 3rd character. Then delete them. How can I do this?
-
I have only one really long line and I want to
Select every 3rd character. Then delete them. The characters could be anything.
How would i do that? -
welcome to the notepad++ community, @Hye-Kan-Chu
here’s a little regex to remove every 3rd character of a long line:
- make a test copy of your file to try this out.
- go to the notepad++ menu
search > replace
and enter the following:
find what:
(.?.?)(.?)
replace with:$1
wrap around: enabled
search mode: regular expression- then hit
replace all
a line like
123123123123123
will now look like this:1212121212
.
or a line likeabc123ABC123+#*123 123
like this:ab12AB12+#12 12
. -
may I ask you why you used the
?
in find what?
It can’t be a non-greedy operator as there is no multiply operator like*
or+
, can it be?
As a dot denotes a single match this(..).
should be sufficient, shouldn’t it?
I know, with regex there are multiple ways to achieve what you want but I
didn’t expect the?
usage so I’m really curious if this was on purpose and what the reason is. -
yes, you are absolutely correct.
no special reason, just accustomed to using the same full syntax modules for everything for my own readability, even if unnecessary if the op doesn’t request more.
hence also the second (), to be able to use $2 without changing the preg_match, if needed in the future.maybe this is typical for me and other pcre php people to easily read and modify pregs on web servers, so you might see very long preg replaces, where you know they can be simplified a lot, but they are perhaps more modular for adaptations than a simplified version.
-
I fully understand the reason for using extra
(
and)
. But, and I think I’m agreeing with Eko here, the?
doesn’t make much sense for the problem statement. :) -
the following things are supposedly relevant:
does it work ?
does it do the job ?
does the syntax produce any issues ?as long as the answers are yes, yes, no, it should be fine.
if you disagree: i’ve already told eko that he is absolutely correct, so take this answer for you too if you like. -
thank you for clarification, very much appreciated.
I always have that kind of feeling that I’ve missed something when I see someone
doing something which I haven’t expected especially in areas where I think I didn’t
really understand most of it. ;-) -
Hi, @hye-kan-chu, @meta-chuh, @ekopalypse, @alan-kilborn and All,
Just a small mistake ! Using your regex S/R :
SEARCH
(.?.?)(.?)
REPLACE
$1
Against your second example
abc123ABC123+#*123 123
does give :ab12AB12+#12 13
( and notab12AB12+#12 12
! )Using the following S/R also gives the same results :
SEARCH
(..).
REPLACE
\1
Cheers,
guy038
-
you are absolutely correct.
this happened due to posting inline code in between ` characters.
please press edit on my post and you will see three spaces instead of one when copying the line.good to know that we must avoid inline coding when posting more than one whitespace, thanks for making me have a look at that 👍
(maybe this happened in the past as well to others, and was the reason why users could not achieve the same, verified results as we do, making us wonder why)apparently this is a limitation of nodebb not rendering nbsp’s on the canvas when using inline span of code highlighting.
original sample code:
before: abc123ABC123+#*123 123 after: ab12AB12+#12 12
ps: my apologies, from now on i will re-copy-paste from a post back to notepad++ to verify a successful, reproducible experience for the op.